Learning Thursday: Maze Tutorial
Happy #LearningThursday, everyone! For today’s Scratch tutorial, we’re going to build a maze for Sprite the cat to go through. You can see what your projects should end up looking like here. Like we told you last week, this week’s tutorial is a little more challenging than the previous week - and they’ll continue to get that way. If you’re a first timer, we recommend going back to our original #LearningThursday post and starting from the beginning! But as always, if you have questions, comments, or want to share your finished product with us, reach out on social media or via email at email@example.com! Let’s get started:
Make a new background with lines for a maze, a green oval to start at, and a red oval for your finishing point.
Let’s make sure Sprite can fit in the maze! With him selected, use the controls that pop up to make him smaller.
From the Events category, use a “when” block to make Sprite move up when you press the up arrow key. Now duplicate that to make him move that way for all the different arrow keys (up, down, right, left).
Just in case we make mistakes and want Sprite to go back to the beginning of the maze (the green oval), let’s make him do that whenever we press the space bar - the same way you did with the arrow keys.
Now we’re going to build the core portion of the game - the code that keeps running no matter what once the green flag is clicked on. As always, start with a green flag block from the Events category. Next, we have to define when we want this code to be happening. Since that’s always, we’re going to put the rest of the blocks in a “forever” loop block, from the Control category.
Let’s make this fun - whenever Sprite hits a black line (a boundary of the maze) we want him to go back to the beginning (the green oval), because that means we lost the game and have to start over. To do that, we’re going to use an “if” block and a “touching color” block to send him back to the x and y coordinates of the starting green oval.
Last but not least, what happens if we win? We’ve got to celebrate! Using the same block logic from the last step, make Sprite go to the center of the maze and say “You Won!” when you get to the end (the red oval).
You’re done! Click the green flag button and make sure you can help Sprite get through the maze with your arrow keys and space bar - and that he celebrates when you win! As the #WeCanChallenge for today, see if you can make it so that Sprite can’t get beyond the walls of the maze. Also, think about what happens if you don’t have a forever loop around your “touching color” blocks.
If you’re stuck and need help, you can see Dr. Guthals’ project here. See you all next week for another tutorial!