Move Inside a Maze - Part 1
I thought a fun Scratch game for right after Halloween would be a game that encourages kids to run away from candies and towards some healthy foods! That's how the idea for the Vita-Man maze game came about. I shared it inside our Facebook group for teachers, and got all the encouragement I needed to start creating the course! The course is still a work in progress, but as I was putting together the first few tutorials, I realized learning how to move a character inside a maze, might make for a really fun lesson I could share with all of you!
Getting a character to move inside a maze is a bit more complex than it might appear at first glance. First, you want your character to move in the direction of the last arrow key pressed, even when that arrow key is no longer pressed. And second, you need a way to keep your character moving smoothly, while at the same time preventing it from going through the walls. This last part means you need a way to detect when your character is getting too close to the wall before it actually touches the wall!
But I'm getting ahead of myself. Let me start by introducing the game and getting you all set up with the starter project. Then, we'll learn how to smoothly move Vita-Man inside the maze...
Introducing the Vita-Man Maze Game!
The short video below covers how the Vita-Man game works. The starter project you'll receive will include all the characters and images you'll need to build this game, and by the end of next week's post, you'll have Vita-Man moving smoothly inside the maze. At that point, you have the choice of giving your students the freedom to complete the game any way they wish, or you could wait for the complete course with all the step-by-step tutorials to come out. Regardless of which path you choose to take, I thought it might be useful to watch this introduction to the game, and maybe even play it for your students. I think it might help give them some ideas and at the very least, get them excited about learning how to move inside a maze!
Play the Game...
Have I gotten you excited yet? Below you'll find the completed Vita-Man maze game! It might be fun to project the game and have students come up and play it while the rest of the class is watching. I've done this in my own classroom, and it sure gets everyone excited about what they're going to learn! It also gives the kids a better idea of what it is they're going to be building and how it's all going to work.
To play the game, just click the green flag and use the arrow keys to move Vita-Man around...
The Starter Project
Click the button below and enter your email address to have the starter project sent to you. The email you'll receive will contain instructions for how to upload the starter project onto your Scratch account, and how to share it with your students.
Step 1: Get Vita-Man Moving!
In this very first step, we're going to learn how to program Vita-Man to move when the arrow keys are pressed. You'll be reminded of how we change 'x' by a positive number to move to the right, and by a negative number to move to the left. Similarly, we change 'y' by a positive number to move up, and by a negative number to move down.
Tip: As you follow the instructions, if you can't remember which category a particular block is in, just remember to pay attention to the color of the block. You'll be able to find the block in the category with the matching color.
Step 2: Move More Smoothly!
Vita-Man is able to move around, but it only moves when an arrow key is pressed. To create smooth movement, we need Vita-Man to keep moving in the direction of the last arrow key pressed even when no arrow key is pressed. In other words, we want Vita-Man to stop only when it reaches a wall! To do this, we'll create a variable to store the last arrow key pressed. We'll then have two processes running simultaneously. The first process will monitor the arrow keys pressed, and keep updating the value of the variable based on the last arrow key pressed. The second process will constantly check the value inside this variable and move Vita-Man accordingly.
Coming up Next...
Can you guess how we're going to go about detecting the maze walls without actually bumping into them? See if you can come up with a guess based on the clue in the image below, and if you want to join the discussion and see what others are thinking, don't forget to join us inside our Facebook group for teachers!
Next week, I'm going to provide you with 4 additional step-by-step tutorials, at the end of which you'll have Vita-Man moving inside the maze like a pro!
See you next week,