Welcome to a fun Scratch tutorial for kids! In this commodity, we'll show you lot how to make a maze in Scratch. We'll offset from the start and demonstrate how to create your own maze, command the character'southward escape from the maze with arrow keys, and even customize the maze with different themes. Allow's go started!

By the way, join our free Scratch class anytime for live expert guidance equally you make cool games.

Screen-Shot-2021-09-07-at-6.19.41-PM

Acquire how to make a maze in Scratch

Check out the maze game nosotros're building here! Follow the steps below to see how to exercise this with Scratch coding. Or watch our helpful video to hear instructions:

1. Fix the maze and character

The commencement thing to do is create the maze. New Scratch projects come loaded with a default bare white backdrop. Click on the backdrop in the bottom right, which will put yous in an edit backdrop mode. Then in the superlative left horizontal carte, click on "Backdrops".

Utilise the line drawing feature (quaternary one down in the left column) to create whatever maze pattern y'all want. Then use the castor characteristic (2nd one downward in the left column), and describe a green pointer at the leave point of the maze. This is important every bit information technology will allow us detect when the actor has solved the maze and display a win message.

How to Make a Maze in Scratch

Then click on the sprite to go back to sprite editing fashion. I'grand using the true cat, only feel gratuitous to utilise whatsoever you want! We want to brand sure our cat is small plenty to travel through the maze. Fix the "Size" feature in the lower right panel to 20.

And so drag the true cat to the superlative left corner of the map as the starting location. Pay attention to the x and y values of the location. In our example, 10 is -180 and y is 120. This information allows usa to always motion the true cat to the peak left location every time nosotros offset the game.

Kids Make a Maze in Scratch

2. Write the code for the showtime of the game

Now it'south time to code! Make certain you lot have clicked the sprite so we are adding code simply for the character.

The get-go cake nosotros desire is "when light-green flag clicked" from Events. Underneath, we want the "get to x, y" Move block. We can fill in the blanks with the values for the top left position. For united states, x is -180 and 120. This allows us to reset the game every time we hit the dark-green flag.

Code the Maze Game

3. Write the code to control the character with arrow keys

Most of our code volition let us to control the cat with our arrow keys. In Events, we want the "when space primal pressed" block, and we demand to change "space" to "right arrow" from the drop downwards.

Nosotros want to connect this to the "change x by 10" Motion cake. This will let us to move to the right every time we press the right arrow. We also need to handle the case if the cat walks into the wall, and we want to terminate whatever movement.

To practice this, nosotros want to add the if/and then block from Control. The if status is the "touching color" block from Sensing. The color volition be the color of the line. Scratch has a really cool feature to become the exact color of the line. When you click the color circle in the sensing block to change it, you will see that y'all can change the color with three sliders.

But to ensure the color is a perfect friction match with the colors of the maze, you can click the symbol that looks similar a background with a dropper on superlative of it. This volition now open up us a view where you lot tin can hover over parts of the background and select a color. In this hover view, click on a line on the edge of the maze, and this will become the maze colour for you.

Match the color for your maze
Build a maze in Scratch

When nosotros bear upon the border of the maze, we desire to disengage the motion we just did. To do this, we want a "change ten" Motion block within the if argument, but nosotros want to alter the number to -10.

Use a change X motion block in Scratch

When we hit the left arrow, we want a similar horizontal motility to happen, only in the leftward direction. Since this code will look similar to the correct motility, we tin can click on the "when right arrow clicked" block and select "indistinguishable".

Duplicate

The merely changes we need to make in this duplicated cake are to change 10 to -10 and alter -10 to 10 (this reverses the move). We also want to switch "correct arrow" to "left arrow".

Left arrow

Now nosotros demand to handle vertical movement. From Events go the "when space cardinal pressed" block and change the key to "up arrow". Since this is vertical motility, we desire to add together the "change y by 10" Motion cake.

Like before, we need an if/then block. The condition remains the aforementioned every bit before: nosotros need a Sensing cake of touching color and nosotros tin can use the aforementioned play tricks to get the exact colour of the maze lines. Within this if cake, nosotros demand to undo the upwards motion, and we can practise that by putting a "alter y" Motility block inside while making certain the number is -10.

Change

Nosotros can duplicate this code for down pointer move through right clicking the "when up pointer central pressed" block and selecting duplicate. And so we need to make the following small changes: switch "up arrow" to "down pointer", modify x to -x, and modify -ten to x. This reverses the motion, which is expected given that up motion and down motion are opposites of each other.

four. Display a win message once the character escapes

We're almost done. The concluding thing we need to take care of is displaying a win message.

To practice this, let's make a new backdrop that represents the win screen. Go to the circular "backdrop add together" button in the very bottom right corner of the screen. Hover over this button, and select the "pigment" icon that is third from the top. Then go to the backdrop editor, and on this blank screen, type a win message similar "Yay y'all win!!". The text editor is third downwardly in the second column.

Display a win message for a Scratch maze

Now we demand to update our code to change backdrops at the correct fourth dimension. Later on the "go to x, y" block that we already have under the "when green flag clicked", we desire to add the two Looks blocks of "show" and "switch backdrop to backdrop1". The "switch backdrop" block has a drop down carte du jour then make sure backdrop1 (or the name of your backdrop that contains the maze) is selected. This allows us to reset to the maze whenever nosotros starting time the game later on switching to the win screen.

After this, nosotros demand to add a "forever" cake from Control since we always desire to detect if we have reached the green arrow, signaling the end of the game. Inside "forever", we desire an "if/and then" construction like to the one we built for detecting if the character walked into a wall.

Nosotros tin can employ the Sensing "touching colour" cake to detect when we take reached the arrow and solved the maze. This time, change the colour in this sensing block to the colour of the arrow using the same hover technique we used to get the color of the maze.

Inside the "if/then" cake, we want ii Looks blocks. We start want "switch backdrop to backdrop2", and brand sure to change the properties to the one with your win message. Nosotros also desire the "hide" block to make the grapheme disappear from the screen so we only accept a win screen. Great chore! You take simply congenital a maze in Scratch!

Customize your maze

5. Customize the maze!

Y'all tin likewise create mazes with themes! We drew our maze on the default white background, just y'all tin kickoff load in one of Scratch's backgrounds, and then describe the maze on top of information technology. And so you lot can option a character that matches your theme. For example, you might make a crab under the bounding main or a monkey in the jungle.

Have fun making a maze in Scratch

We hope you had fun making your maze game! In this article, you learned how to build a maze and helped a cat escape from it. Check out our Scratch coding for kids classes to learn how to brand other games and animations. Up adjacent, learn how to make a Pacman game in Scratch with a simple tutorial.

Screen-Shot-2021-09-07-at-6.19.41-PM

Written by Sophie Andrews, a Create & Acquire instructor. Sophie Andrews is a educatee at Stanford University studying Math and Computational Sciences. She loves teaching and is a didactics banana for Stanford's introductory calculator science classes. Her work focuses on data scientific discipline. Final year she built the online National Vote Trackers for The Cook Political Report, and she currently leads the Data Team at The Stanford Daily. She'south as well interned with the FCC and the National Renewable Energy Lab.