Welcome to a fun scrape tutorial because that kids! In this article, we’ll show you how to do a maze in Scratch. We’ll begin from the beginning and also demonstrate just how to develop your very own maze, regulate the character’s escape from the maze with arrow keys, and even customize the maze with different themes. Let"s gain started!

Learn exactly how to do a maze in Scratch

Check the end the maze game we’re building here! monitor the steps listed below to see exactly how to execute this with scratch coding. Or watch our helpful video clip to hear instructions:

1. Set up the maze and also character

The an initial thing to execute is create the maze. New Scratch projects come loaded through a default blank white backdrop. Click the backdrop in the bottom right, i beg your pardon will put you in an edit backdrop mode. Climate in the height left horizontal menu, click “Backdrops”.

Use the line drawing feature (fourth one down in the left column) to produce whatever maze sample you want. Then usage the brush feature (second one under in the left column), and draw a green arrow at the exit allude of the maze. This is crucial as it will certainly let united state detect as soon as the player has actually solved the maze and also display a success message.

*

Then click on the sprite to get earlier to sprite editing and enhancing mode. I’m utilizing the cat, but feel complimentary to use whatever you want! We want to make certain our cat is small enough come travel v the maze. Set the “Size” function in the reduced right panel to 20.

Then drag the cat come the height left corner of the map as the beginning location. Pay fist to the x and also y values of the location. In our example, x is -180 and also y is 120. This information allows us to constantly move the cat to the top left location every time we start the game.

You are watching: How to make a maze game on scratch

*

2. Compose the password for the begin of the game

Now that time to code! Make sure you have actually clicked the sprite so we are including code just for the character.

The very first block we want is “when environment-friendly flag clicked” from Events. Underneath, we desire the “go to x, y” Motion block. We deserve to fill in the blanks with the values for the optimal left position. For us, x is -180 and also 120. This enables us to reset the game every time us hit the green flag.

*

3. Compose the code to manage the personality with arrowhead keys

Most that our password will enable us to manage the cat v our arrow keys. In Events, we want the “when space vital pressed” block, and we need to readjust “space” to “right arrow” indigenous the drop down.

We want to attach this come the “change x through 10” Motion block. This will allow us to move to the ideal every time we push the right arrow. We likewise need to handle the case if the cat walks into the wall, and we want to stop any kind of motion.

To perform this, we desire to include the if/then block indigenous Control. The if condition is the “touching color” block native Sensing. The color will it is in the color of the line. Scratch has actually a yes, really cool attribute to gain the exact shade of the line. As soon as you click the shade circle in the sensing block to change it, friend will see that friend can readjust the color with 3 sliders.

But come ensure the color is a perfect match with the colour of the maze, you deserve to click the symbol that looks prefer a background with a dropper on height of it. This will now open united state a see where you deserve to hover over parts of the background and also select a color. In this float view, click on a heat on the leaf of the maze, and also this will gain the maze color for you.

*
*

When us touch the sheet of the maze, we desire to undo the movement we just did. To do this, we desire a “change x” Motion block within the if statement, however we want to change the number come -10.

*

When we hit the left arrow, we want a similar horizontal activity to happen, but in the leftward direction. Because this code will certainly look similar to the right movement, us can click on the “when right arrow clicked” block and select “duplicate”.

*

The only alters we should make in this replicated block room to readjust 10 come -10 and change -10 come 10 (this reverses the motion). We likewise want to switch “right arrow” to “left arrow”.

*

Now we require to handle vertical movement. Indigenous Events obtain the “when space an essential pressed” block and readjust the crucial to “up arrow”. Due to the fact that this is vertical movement, we want to add the “change y by 10” Motion block.

Like before, we require an if/then block. The condition remains the very same as before: we need a Sensing block of emotional color and also we have the right to use the same trick to gain the exact color of the maze lines. Within this if block, we need to undo the upwards motion, and also we have the right to do that by putting a “change y” Motion block inside while making certain the number is -10.

*

We have the right to duplicate this code for down arrowhead movement through best clicking the “when increase arrow crucial pressed” block and selecting duplicate. Then we have to make the following small changes: move “up arrow” come “down arrow”, change 10 come -10, and readjust -10 to 10. This reverses the motion, i m sorry is expected provided that increase motion and also down movement are opposites of every other.

*

4. Screen a success message once the personality escapes

We’re nearly done. The last thing we should take treatment of is displaying a victory message.

To carry out this, let’s make a brand-new backdrop the represents the success screen. Walk to the round “backdrop add” switch in the very bottom right corner of the screen. Hover over this button, and select the “paint” symbol that is 3rd from the top. Then go to the background editor, and also on this empty screen, form a win blog post like “Yay you win!!”. The message editor is third down in the second column.

*

Now we need to update our code to adjust backdrops at the exactly time. After the “go come x, y” block the we currently have under the “when green flag clicked”, we desire to include the 2 Looks block of “show” and “switch backdrop to backdrop1”. The “switch backdrop” block has actually a fall down menu so make certain backdrop1 (or the surname of her backdrop that has the maze) is selected. This enables us come reset come the maze whenever we start the game after switching to the victory screen.

After this, we need to include a “forever” block indigenous Control because we always want come detect if we have reached the eco-friendly arrow, signaling the end of the game. Within “forever”, we desire an “if/then” structure comparable to the one we built for detecting if the character walked right into a wall.

We deserve to use the Sensing “touching color” block come detect once we have actually reached the arrow and solved the maze. This time, change the shade in this sensing block come the color of the arrowhead using the same hover method we used to get the shade of the maze.

Inside the “if/then” block, us want two Looks blocks. We very first want “switch backdrop to backdrop2”, and also make sure to readjust the backdrop to the one through your victory message. We also want the “hide” block to make the character disappear from the screen so we only have actually a win screen. Great job! You have just developed a maze in Scratch!

*

5. Customize the maze!

You can additionally create mazes with themes! We attracted our maze ~ above the default white background, however you can an initial load in one of Scratch’s backgrounds, and also then draw the maze on peak of it. Climate you deserve to pick a character the matches your theme. For example, you could make a crab under the sea or a monkey in the jungle.

Have fun making a maze in Scratch

We expect you had fun making her maze game! In this article, you learned how to build a maze and also helped a cat escape from it. Inspect out our scrape coding for youngsters classes to learn how to make other games and also animations. Up next, learn just how to make a Pacman video game in scrape with a basic tutorial.

See more: Puntos Rojos En La Lengua Y Solemos Ignorar (Preferirías No Tenerlas)

Written by Sophie Andrews, a develop & learn instructor. Sophie andrew is a student at Stanford University researching Math and also Computational Sciences. She loves teaching and is a to teach assistant for Stanford"s introductory computer system science classes. She work focuses on data science. Critical year she built the online national Vote Trackers for The chef Political Report, and also she currently leads the Data Team at The Stanford Daily. She"s also interned v the FCC and also the national Renewable power Lab.