Mazes are a great game to make in Scratch, for either new comers or pros. In this guide you’ll learn to design a custom map and then code the game to send you back to the start if you touch the walls or one of the enemy sprites. We’ll also show you how to create cool power-ups to help you whizz past enemies or shrink through tiny gaps.
After visiting the Scratch website, hit CREATE and start a new project.
The first task is to design your maze, so click STAGE on the right hand side and then BACKDROPS. This is where we’ll put our maze artwork.
To design your maze, either use the line tool for straight lines or the paintbrush tool for freehand lines. Its really important that you only use one colour for your maze.
Top Tip: Don’t forget to make your maze big enough for your character to move through. If you need to change your character size, simply click on the sprite and then adjust the SIZE number (below the game window).
Now we’ve got our first level, lets get our character moving. In this game the player will navigate the maze with their mouse, with the sprite following them as they move.
So, we want to tell the computer ‘If the computer mouse is touching the sprite, make the sprite go to the mouse’s position’.
We also need to put this selection of blocks inside a forever loop as we want the computer to be constantly checking if the mouse is touching the sprite. If its not inside a forever, it’ll only check once at the start.
In this game, if the player touches the walls they get sent back to the start. For this we’re going to use “colour sensing”.
Your code wants to say “if the sprite is touching a certain colour, then send that sprite back to the beginning”. For this, you’ll need to tell the computer two things. First, what colour and secondly where the beginning is.
The colour and coordinates in the example shown are unique to the map layout, so yours might be different.
If we want to add extra maze levels to the game, we need something to act as a checkpoint to tell the computer we’ve reached the end of the maze.
Create a new sprite and call it checkpoint, in this example we’ve used a flag from the Scratch library but it could be whatever fits in with your theme!
Now you can design your new levels, but don’t forget to keep the colour exactly the same so the code still works! If you changed colour then the easiest way to find the previous one is to use the pipette tool shown in the second image.
To make the game switch levels, we need to tell it two things. First, what backdrop if needs to show when the game starts and second, what backdrop to display when touching the checkpoint sprite.
Remember, this all needs to go inside the forever loop otherwise it’ll only check once!
Why not take your game further and add power-ups. Lets add a power-up that allows us to shrink to a tiny size and squeeze through smaller gaps in the maze.
First off, lets add a power-up sprite.
Now, if we add code that says “If player touching power-up sprite, then SET size to 25” – this would shrink the player to a quarter of their size allowing them to squeeze through tiny gaps! Remember, we also need to tell the game what size our player sprite will be when the game starts too.
Top Tip: if you only want your power-up to appear on certain levels, use the “When backdrop switches to…” block in the events tab.
Congratulations – you just finished your maze game! What else could you add next? More levels? Sound effects? Heres one we made using this guide – try it out and let us know what you think.