Introduction to Programming

Activity 1: Giving Beetle its Moves

Lesson 9: Beetle in a Maze

Welcome to the Beetle in a Maze project! Over the next two activities, we will program a beetle sprite to navigate through a maze. In this first activity, we will set up the maze and give the beetle its movement controls.

PictoBlox stage showing a maze backdrop with a beetle sprite at the starting position

Setting Up

  • Open PictoBlox and create a New File.
  • Select Block Coding as the coding environment.
  • Add a maze backdrop from the backdrop library or draw one using the paint editor.
  • Add a Beetle sprite (or any bug-like sprite) from the sprite library.
  • Position the beetle at the entrance of the maze.

Programming the Movement

We will control the beetle using the arrow keys. Each key press will move the beetle a small number of steps in the corresponding direction. You will find the blocks in the mentioned palettes:

  • When (right arrow) key pressed — Events: Point in direction 90, Move 5 steps
  • When (left arrow) key pressed — Events: Point in direction -90, Move 5 steps
  • When (up arrow) key pressed — Events: Point in direction 0, Move 5 steps
  • When (down arrow) key pressed — Events: Point in direction 180, Move 5 steps
Four block coding scripts each triggered by an arrow key — each points the beetle in the correct direction and moves it 5 steps

Setting the Starting Position

  • Add a 'When flag clicked' block.
  • Connect a 'Go to x: () y: ()' block with the coordinates of the maze entrance.
  • Add a 'Point in direction 90' block to ensure the beetle starts facing right.
Block coding script showing when flag clicked, go to starting coordinates, and point in direction 90

Testing the Movement

  • Click the green flag to start.
  • Use the arrow keys to move the beetle around.
  • Make sure the beetle moves smoothly in all four directions.
  • Try navigating through the maze manually!
Save your file with the name Beetle in a Maze before moving on to Activity 2!

Subscribe to our newsletter.

Get updates to news and events.