A maze is a simple puzzle where you try to find your way from the beginning to the end. Completing a maze tests your memory, problem-solving skills, and patience. Coding does the same! Both require having to think logically and in order.  

In this tutorial, I’ll show you an easy and fun way to code a maze in Scratch where you control the player with your arrow keys. As a bonus, I’ll also teach you how to animate your character and add a timer. 

You can learn to build a maze and other fun Scratch games with a live instructor in our top-rated coding classes. My elementary school students really enjoy how engaging and easy Scratch coding is. They just have to drag and drop to create cool games and programs. By coding a maze, we’ll learn about loops, collision detection, and events. 

Complete this tutorial to code a maze Scratch!

Completed maze game

Play and remix the complete maze game now. 

In this game, the baby penguin, Pesto, has lost his hat. Mom is going to be mad! Help him find his winter hat to win.

We can break down this game into 3 main components: 

1. The maze: A drawing of a maze obstacle players have to avoid and make their way through.

2. The player: the player, the penguin, moves around the maze and returns to the beginning when they touch the edge.

3. The goal: the goal, the winter hat, is placed at the end of the maze and the player wins when they reach the goal.

What you need:

Scratch account: Create a free Scratch account

No coding experience is necessary for this Scratch tutorial. Beginner-friendly for kids ages 8 and up. Give it a try!

Steps to Make a Maze Game in Scratch

Let’s turn each of the parts we discussed previously into steps:

  1. Create a new Scratch project
  2. Add a backdrop
  3. Draw the maze
  4. Add and position the player 
  5. Move the player around the maze
  6. Detect player collision with the maze
  7. Add and position the goal
  8. Detect player collision with the goal

Step 1: Create a New Scratch project

First, we need to set up a new project in Scratch where we will edit our code. 

Create a new Scratch project
Name Scratch project Penguin maze game

Now we have a fresh new project to code our maze game!

Hint: You can also remix the Penguin Maze project to see the completed code.

Step 2: Add a Backdrop

Set the stage for your game by adding a background image.

Choose a backdrop button
select the arctic backdrop in scratch

You should now see the backdrop in your preview area. 

see the backdrop in Scratch preview

Hint: Get creative and select a backdrop that matches your theme. You can also select Surprise to let Scratch choose for you. 

Step 3: Draw the maze

A maze is simple to draw with just horizontal and vertical lines. We’ll draw our own maze, make sure you leave enough room for your player to get through. 

select paint button
outline maze sprite
rename the maze sprite

Do you see your maze in the preview screen like this? Great!

see the maze in the preview

Hint: You can make the maze as easy or hard as you want. Add more lines and dead ends to make the maze harder. 

Step 4: Add and position the player

We want to add our player, the penguin. The penguin is going to start at the top left every time the game starts. Before we move the penguin, position it at the top with our code.

choose a sprite button
select the penguin sprite
change the penguin sprite size

Next, add this code to the penguin so that it goes to the starting position every time the game starts. 

go to x y
see the penguin move

Now, try moving your player away from the starting position. When you click the green flag, it should return there. If your test works, you’re ready for the next step. 

Hint: You can get creative and draw your own sprite, just hover over the add a sprite button and go up to Paint.

Step 5: Move the player around the maze

The penguin is on the screen, but he can’t move. The penguin needs to move up, down, right, and left when we press the arrow keys. We need to control him with the arrow keys.

Let’s add the logic to the arrow keys. To move the sprite right and left, add this code: 

when right or left arrow key pressed blocks

To move the sprite up and down, add this code: 

when up or down arrow key pressed blocks
complete code for penguin movement

Your penguin can move now! Try pressing the arrow keys and make sure the penguin is moving in the right direction.

Hint: To move the player faster or slower, change the x and y values. 

Step 6: Detect player collision with the maze

We need to code what happens when the player touches the maze. The penguin should say ‘Oh no!’ and go back to the starting position.

detect a collision with if then block
detect a collision final code

Now, you can try touching the maze with your player sprite. Does it return to the starting position?

It’s working, let’s keep going! 

Hint: You can customize the message your sprites says or change what happens after the sprites touch. 

Step 7: Add and position the goal

Our player is in place and can move around the maze. Now, let’s place the goal at the end of the maze. 

choose the winter hat sprite
change your maze to size 40
position the hat
position the hat code

Once you’re done, click the green flag to test your game. Your hat should go to the end of the maze when the green flag is clicked.

Hint: You can customize the goal sprite to fit your theme by drawing or uploading a sprite.

Step 8: Detect player collision with the goal

To win the game, the player needs to reach the goal. When the player teaches the goal, they say “I found it!” and the game ends.

detect a collision with the goal
penguin code for collision detection

Hint: You don’t have the complete the maze to test your game. Just drag your character sprite to the end in your game preview.

Your maze game is complete! Play the maze game.

Click the green flag and give it a try. If you want to share it with other people and let them remix it, click the “Share” button at the top. 

completed maze game gif

You can “see inside” the completed maze game to view the full Scratch code. 

Challenge yourself by adding the bonus features to your maze. 

Bonus: Animate the player 

We can animate the penguin by making it look left and right when it moves. To do this, we’ll create a costume for each look.

1. Create the costumes

costumes tab in scratch
choose the look front penguin costume
duplication the look right costume
flip the costume horizontal

The final costumes will look like this:

rename the costume look left

Your penguin now has different costumes to show which direction he’s facing.

2. Change the costume with arrow keys

Go back to the Code tab to add code to the penguin sprite. Under each key press, we will switch the costume to match the direction the penguin is facing.

switch costumes block added to arro key blocks

Try pressing the arrow keys and see if your penguin is facing the right direction.

3. Set the costume when the game starts

But, when we press the green flag the penguin isn’t always facing forward.

switch costume to look front
completed code to switch costumes

Start the game over by pressing the green flag. Your penguin should start looking forward, then look right or left depending on which direction it’s moving. 

Now your penguin is animated to look like it’s walking.

Bonus: Add a timer 

We can add a timer to make the maze more challenging. Let’s give the player 60 seconds to complete the maze game before the penguin disappears.

1. Create a Time variable

A variable is used to hold information that changes. Our time decreases every one second, so we can use a variable to save that value.

You should see the Time variable in your game preview now.

2. Start the Timer 

If we want the player to have 60 seconds to play, we should set the timer to start at 60. 

set time to 60

Press the green flag to see the time reset.

3. Count down the timer

Use a loop to count down the timer every 1 second. 

loop to count down the timer
showing timer in game preview

Press the green flag to see the time counting down.

4. Show and hide the penguin

The penguin should show when the game starts, but hide after the time runs out. 

add show and hide blocks
show and hide penguin

That’s it! Press the green flag to test your timer one more time. It should be counting down the time and hiding the penguin once the time runs out.

Give yourself a pat on the back. You completed the maze game tutorial. See the complete game with bonuses and remix it

More Scratch Tutorials for Kids

Try making another Scratch game using a fun step-by-step tutorial:

Download Free Printable Scratch Coding Tutorials PDF

Get the Rocketship Landing game and Flying Space Cat Scratch tutorials in a printable format.

Code more games in Scratch!

Continue coding games in Scratch with the guidance of a live, expert instructor. We teach kids how to code and practice analytical thinking, computational thinking, problem-solving, and logical reasoning.

Kids, ages 8-10, who want to learn more about Scratch coding can join the Elementary School Core Track. We offer a structured Scratch curriculum with project-based learning for hands-on practice. Enroll today to get started.

Learn to make games in Scratch in our top-rated coding classes for kids.