Table of Contents

Beetle in a Maze

Beetle in a Maze - STEM activities
Project Description

Introduction

The time has come to do something super exciting! We are going to create an interesting game in PictoBlox! The aim of the game to help the beetle reach the apple at the end of the maze without touching the boundaries.

We are going to use evive’s navigation key to control the beetle.

Let’s begin!

Bringing in the Beetle

PictoBlox has an inbuilt library from where you can choose any sprite you want. Follow the steps below to bring in the beetle:

  1. Right below the stage, you will see a purple button with a bear on it. Take the cursor over it and select Choose a Sprite; the sprite library will open.New Sprite
  2. Select the beetle sprite from the library.

Now, there are two sprites: beetle and Tobi. Right click on the icon for Tobi (below the stage) and click on the delete option.TobiDelete

BettleInStage

Giving the Beetle Its Moves

Let’s write the script for the beetle. Since we’re controlling it using evive’s navigation key, the beetle must move in the direction we push the key. Let’s begin!

  1. Connect evive to your computer and open PictoBlox. Then, select evive as your board from the Board menu in the menu bar and select the appropriate port from the Connect menu. In doing so, some palettes specific to evive will appear in the block palette.
  2. To make the beetle point in a direction, we will use the point in direction () block from the Motion palette. Drag and drop it in the scripting area and write 0 in the space. 0 corresponds to the forward direction (w.r.t. the end of the maze).
  3. To move the beetle, drag and drop move () steps below the point in direction(0) block. Now, click on these blocks; the beetle will move 10 steps forward.
  4. From the evive palette, drag and drop the navigation key is in state () ? block and select up from the drop-down.
  5. To make the beetle move forward only when we press the navigation key, we will use the if block from the Control palette.
  6. Place the navigation key is in state () ? block inside the space in the if block. Place the point in direction () and move () steps blocks inside the C shape.
  7. The steps for writing the script for the down, right, and left directions are similar to those for right. So, instead of dragging and dropping each block, just duplicate the script as shown by right-clicking on it and make changes in the state in the navigation key is in state () ? and point in direction () blocks as given below:
    1. For ‘down’, set the direction as 180.
    2. For ‘right’, set the direction as 90.
    3. For ‘left’, set the direction as -90.Beetle Navigate Duplicate
  8. Now stack all the if blocks together.
  9. To make our device continuously check and execute these instructions, drag and drop the forever block from the Control palette on the script we’ve written so far.
  10. Finally, go to the Events palette and select the when flag clicked block; place it above the forever block. The script is ready!Bettle1
  11. To test the script, upload the firmware to evive using the Upload Firmware button and click on the green flag. The beetle should move as you press the navigation key.
evive Alert
NEVER center press the navigation key. Otherwise, communication between evive and your computer will stop. In case you press it by mistake, stop the script, reset evive, and run the script again.

Setting Up the Stage

PictoBlox has an inbuilt library from where you choose any backdrop you want. Follow the steps below to add the maze backdrop:

  1. Click on the purple colored icon which says Choose a Backdrop. Choose Backdrop
  2. Select the maze backdrop from the library.Beetle in a Maze
evive Notes Icon
Whenever you add a new backdrop or a sprite, the scripting area becomes empty. To get back to the script you were writing, click on the icon of the sprite you were working on, in our case the beetle.

Sensing the environment

Now, it’s time to write the script for safely taking the beetle to the end of the maze. Follow the steps below to write the script:

evive Alert
Make sure that the beetle’s icon is selected.
  1. Go to the Events palette and drag and drop when flag clicked block in the scripting area.
  2. From Motion palette, drag and drop the point in direction () block below the when flag clicked block.
  3. Then, drag and drop the glide () secs to x: () y: () block and set secs as 0.5, x as -150 and y as -150. The x and y values are the coordinates of the beetle’s initial position.
  4. Drag and drop the set size to () % block from the Looks palette to adjust the beetle’s size.Beetle Initialisation
  5. Whatever we write next must execute continuously because we want to keep track of whether the beetle touches the boundaries or not. So, drag and drop a forever block.
  6. Drag and drop an if block inside the forever block and the touching color () ? block from the Sensing palette inside the space of the if block. This block will help us check if the beetle touches the boundaries. Select the color of the boundaries from the drop-down.
  7. Whenever the beetle touches any boundary it should return to its initial position and if it safely reaches the end, i.e. touches the color red, the game should stop. For that, we will use the stop () block.

Below is the complete script.Bettle-2

Enjoy the game!

Conclusion

In this chapter, you made your very first game in PictoBlox! In the coming chapter, we’re going to make another interesting game which will be a little challenging than this one and double the fun!

Project Downloads - Code and Files

Code LabelCode File
PictoBlox Code for Beetle in a Mazehttps://ai.thestempedia.com/wp-content/uploads/2023/05/Beetle-in-a-Maze-2.sb3

Explore Related Projects by STEMpedia

Level up your robot control skills by learning how to control a 2-Wheel Drive Robot with hand gestures using PictoBlox AI's Machine Learning extension. Get ready to channel your inner Jean Grey!
Learn how to make a two-wheel-drive robot and code on the go with PictoBlox's mobile app. Control your robot in real-time with your smartphone!
Learn how to make an automatic chocolate dispenser to delight Santa this Christmas. All components can be found in the evive Starter Kit. Let's begin!

Explore Community Projects