top of page
7995d08fbf39d76da1662e0b0acc5a5c0ebf3284

This walkthrough will show you how to create a maze game in Scratch. It is split into the following sections:

​

  1. Creating the First Level

  2. Choosing the Main Character

  3. Animating & Moving the Main Character

  4. Back to the Start

  5. Adding Score & Time

  6. Making Enemies

  7. Adding More Levels

  8. Extensions

Use the links  to move between sections easily!

1. Creating the First Level

The very first thing to do is to create the level in which our character will move around in!

 

We are going to draw a background from scratch which our hero will run around in to get to the end.

​

Important parts of the pictures are highlighted in yellow!

1. Select the blank Stage button in the button left to edit the background.

Drawing the Background

Challenge Task

Anchor 1
1-11.png

2. Press on the Backdrops tab. This will show Scratch’s own paint editor on the right.

2-1.png
3-2.png

3. Use the line tool to create straight maze lines on the background. Use the slider at the bottom to increase the width of the line.

 Remember this is only the first level so don’t make it too difficult.

41.png

4. Create a start zone and an end zone with the rectangle tool and then fill them in with the fill bucket tool.

 

You can also change the main background colour using the fill bucket tool.

 

Remember to choose an appropriate level name in the text box at the top.

Level Name

Rectangle Tool

Fill Bucket Tool

4-1.png

Make your game more exciting by creating themed levels, like this park background. Other ideas might include a classroom, library or car park.

 

 Try switching up the start and end zones by using the circle tool or the line tool and the fill bucket.

Come back to this challenge when you are ready to make more levels!

2. Choosing the Main Character

Now that you have your first level designed we can make our hero character who is going to navigate the maze and try to get to the end.

Picking the main character

Anchor 2
5-1.png

1. A character is called a sprite.

 

We will choose a sprite from Scratch’s sprite library. Click on the fairy icon to open the sprite menu.

5-2.png

2. I have selected the Animals category on the left menu.

​

I have chosen the Penguin sprite but choose whichever character you want.

3. Press the Costumes tab and check that your chosen sprite has at least two costumes.

 

We will use these to create animation in the next section to make it look like the sprite is moving.

5-3.png

4. Now that we don’t need the cat anymore we can delete him by right-clicking on his icon and selecting delete.

5-4.png

Shrink the Main Character down to size

Shrink Tool

5. The sprite is too big for the level background and you will need to shrink them down.

 

 Click on the shrink button at the top of the program and then click on the sprite in the paint area to shrink them down.

 

Remember how many times you clicked the sprite to shrink it. You will need to shrink both costumes the same number of times.

 

Here I have shrunk my penguin by 17 clicks when I selected the shrink tool. You can compare the size of your costumes by looking at the image size beneath the icon (e.g. 40 x 53).

Picture Size

5-5.png
5-6.png

6. You need to make sure that your sprite is in the centre of the grid otherwise it might cause trouble later when you try to move them.

 

Click on the costume centre button in the top right (it looks like a crosshair) and drag your sprite into the middle if it is not.

 

Make sure that both costumes are in the centre.

 

Also, give your costumes appropriate names, I have named mine Mr. Penguin 1 and Mr. Penguin 2.

Costume Name

Costume Centre

3. Animate & Move the Main Character

Adding Animation

Anchor 3
6-11.png

1. Click on your sprite icon in the bottom left and then on the Scripts tab in the top centre.

 

We will begin using the script blocks and we need to start in the Events category with:

​

 

 

...so drag it over to the script area.

​

This script will run all the blocks that we place beneath it, when the flag is pressed to start the game.

1.

2.

You can only add animation if the sprite you chose has at least two different costumes!

6-2.png
2.0_Forever.png
2.0_When_Green_Flag_Clicked.png

2. The second block we need is: 

 

​

​

...in the Control category.

 

Every block that we put inside the forever loop block will repeat again and again.

 

We want our character to switch between their costumes infinitely to make it look like they are always walking, which is why we use the forever loop.

2.0_Switch_Costume_to_().png
6-3.png

3. Click on the Looks category and drag two...

 

​

 

...inside of your forever loop.

 

Use the drop down list (small black triangle on the costume block) to make one block switch to your first costume and the other block switch to your second costume.

6-4.png
Scratch-Control-Blocks_wait-rvp40w-ucwnu

4. In the Control category, drag over two

​

​

​

blocks and place one after each of your ‘switch costume to‘ blocks.

 

1 second is too long to wait so click on the 1 and change both to 0.5 instead (this is half a second).

If you’ve got the code correct so far, when you press the green flag your character should be animated!

animate.gif

Moving the Main Character

1. In the Events category drag a

 

​

 

into the script area.

 

Change the button from space to ‘up arrow’ (or any key you like) It is also popular for computer games to use the w key to move up.

6-5.png
scratch_key_pressed_block.png
6-6.png
2.0_Move_()_Steps.png
2.0_Point_in_Direction_().png

2.  Click on the Motion category and move over two blocks:

 

​

and

​

​

Change the angle of direction from 90 (which is a right turn) to 0 (which is an upwards turn).

 

Now you have just created code to make your character move upwards by ten steps when you press the up arrow! 

Once you have dragged the blocks when the up arrow is pressed, you can work out how to make your character move down, left and right ALL BY YOURSELF.

​

Add this code in now, before you move on.

Rotate the Main Character

If you press the green arrow and move your character around you might notice that it doesn't rotate when it moves.

 

Click on the i in the top left of your sprite icon in the bottom left.

6-7.png

There are three types of rotation to choose from. Select your preferred style by clicking on one of the three symbols.

6-8.png
walk1.gif

Full Rotation will turn your sprite up, down, left and right.

walk2.gif

Horizontal Rotation will only turn your sprite left and right.

walk3.gif

No Rotation will not turn your sprite at all. it will always appear in the same direction.

Anchor 4

4. Back to the Start

Starting in the right place

7-1.png

We always want the main sprite to start in the green zone when the green flag is pressed to start the game. 

​

First drag your sprite to the green zone.

 

Then go to the Motion category and drag over:

 

 

 

 ...and connect it directly underneath the

​

​

​

block you dragged over earlier.

2.0_Go_to_X_()_Y_().png
2.0_When_Green_Flag_Clicked.png

Once you’ve added that line of code, click the green flag to make sure that the sprite starts where you want it to. If it doesn’t, then you can change the x (horizontal) and y (vertical) co-ordinates by clicking on the white boxes and changing the values.

Back to the start if touching the walls

1. Drag over and connect together the two blocks below:

7-2.png
2.0_When_Green_Flag_Clicked.png
2.0_Forever.png

2. Drag over the two blocks below, put the blue one inside the other and then put them both inside the forever loop:

7-3.png
scratch-control-blocks_if-then1.png
2.0_Go_to_X_()_Y_().png

3. Change the co-ordinates in the blue block you just added so that it matches the same co-ordinates as the block to make the sprite start at the green zone.

4. Now to add the wall detection code!

 

In the Sensing section, drag this block over...

 

 

 

...and put it inside the top of the ‘if then‘ block.

​

Make sure that you put it between the 'if' and 'then' and not underneath.

2.0_Touching_Color_().png
7-4.png

5. Click once on the box in the ‘touching colour‘ block and then click the wall or obstacle you want the player to avoid,

colour.gif

Now is a good idea to play your game and make sure you can get to the end without being teleported back to the start.

 

 If your game is impossible you will need to edit the background – click on the stage icon in the bottom left then the Backdrops tab and edit the walls.

Anchor 5

5. Adding Time & Score

Recording the Time

1. Click on the Stage icon in the bottom left, we will create new code in the Scripts tab of the stage.

 

DO NOT click the character sprite!

 

Click on the Data category and choose Make a Variable.

​

A variable is something that can change.

 

Call your new variable Time.

Adding a Score - The Number of Restarts

8-1.png

2. From the Events category drag:

​

​

​

...then look in the Data category and connect this underneath: 

​

​

​

...but it should say Time instead of 'variable'.

​

This code makes the time start at 0 when the game begins.

2.0_Set_()_to_().png
8-2.png
2.0_When_Green_Flag_Clicked.png
8-3.png
2.0_Change_()_by_().png

3. Now we need a loop that increases our variable called Time by 1 every second.

 

First drag over a forever loop:

​

​

​

Then place inside of it two blocks:

​

​

​

​

Make sure it says Time instead of variable.

​

Now press the green flag to see the timer go up.

2.0_Forever.png
Scratch-Control-Blocks_wait-rvp40w-ucwnu

1. In the Data section click on Make a Variable and give it an appropriate name like Restarts.

 

This variable will count how many times we have touched a wall and had to start again.

8-4.png
8-5.png

2. Firstly, go back to the Scripts area for your character – click on the sprite of your main character in the bottom left then the Scripts tab.

 

You need to add two blocks from the Data category:

​

​

​

Change variable to Restarts and place it directly underneath the flag. 

​

​

​

Change variable to Restarts again and place this code directly after the 'go to' block inside the loop. 

​

Now whenever you touch the wall you restart and it records it in the variable called Restarts.

2.0_Set_()_to_().png
2.0_Change_()_by_().png

6. Making Enemies

Anchor 6

1. Select the fairy icon in the New sprite section to open the Scratch sprite library.

9-1.png
9-2.png

2. From the sprite library choose your enemy. I have selected the polar bear because it fits with my penguin.

3. Select the shrink tool at the top of the program and click on the enemy.

 

Then drag them to where you want them to start.

9-3.png
9-4.png

4. Click on the sprite icon of your enemy then select the Scripts tab. Drag and connect two blocks:

2.0_When_Green_Flag_Clicked.png
2.0_Go_to_X_()_Y_().png

5. From the Control category grab a:

 

 

 

...and place it after the ‘go to‘ block.

 

Now we will make our enemy glide from his start position to somewhere on our level again and again.

 

Move the enemy to where you want it to go to then add:

 

 

...inside the forever loop.

 

Drag anotherglide‘ block and place it underneath but change those co-ordinates to the same as the one underneath the the ‘when green flag clicked‘ block.

​

This code makes the enemy move backwards and forwards forever.

2.0_Forever.png
2.0_Glide_()_Secs_to_X_()_Y_().png
9-5.png

6. Make your main character return to the start if they touch the enemy.

​

Click on your main character sprite in the bottom left and then the Scripts tab.

​

You need to copy the exact same code you made earlier to see if the main character is touching the wall, but this time you need to use:

​

​

​

...instead of the touching colour block.

​

Click on the box in the block and select your Main Character.

​

9-1.png
2.0_Touching_().png

7. New Levels

Anchor 7

Coming

Soon

To be added soon.

This concludes the walkthrough for a Scratch maze game! Try a combination of the suggestions below to add complexity to your game:

​

  • Using ‘say‘ or ‘think‘ blocks in the Looks category to make your sprites say things at certain points (like at the start of a new level).

  • Making your game harder by speeding up enemies in later levels (you could change the number of seconds it takes to glide)

  • Adding more enemies that only appear in harder levels.

  • Setting a time limit – instead of having your time begin at 0 and increasing by 1 every second, have it start at 30 and decrease by 1 every second.

Extensions

Anchor 8
7995d08fbf39d76da1662e0b0acc5a5c0ebf3284
bottom of page