The beetle can now move — but it can walk right through the maze walls! In this activity, we will use sensing blocks to detect when the beetle touches the walls and stop it from passing through them. We will also detect when the beetle reaches the exit!
Sensing Blocks in PictoBlox
The Sensing palette in PictoBlox contains blocks that allow sprites to detect their environment — including touching other sprites, colors, or the edges of the Stage.
Key Sensing Blocks
Detecting Wall Collisions
We will use the 'Touching color?' block to detect when the beetle touches the wall color of the maze. When it does, we will move it back to prevent it from passing through.
- Identify the wall color of your maze (e.g. black or dark blue).
- Add a 'When flag clicked' block with a Forever loop.
- Inside the loop, add an 'If (touching color [wall color]?) Then' block.
- Inside the If block, add a 'Move -5 steps' block to push the beetle back.
- This will prevent the beetle from passing through walls.

Detecting the Exit
Now let's detect when the beetle reaches the exit. We will mark the exit with a distinct color (e.g. green) and use the 'Touching color?' block to detect it.
- Color the exit of the maze with a distinct color (e.g. green).
- Inside the Forever loop, add another 'If (touching color [exit color]?) Then' block.
- Inside it, add a 'Say (You made it! Well done!) for 3 seconds' block.
- Optionally, add a 'Stop all' block to end the program when the exit is reached.

Running the Game
- Click the green flag to start.
- Use the arrow keys to navigate the beetle through the maze.
- Try to reach the exit without touching the walls.
- The beetle will be pushed back if it touches a wall, and it will celebrate when it reaches the exit!

.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)