Mouse Maze (Part 1)

We’re going to use scratch to make a game. A mouse will have to find his way through a maze to get his cheese without touching the walls.

Setting Up the Project

The first thing we need to do is give our project a name. Find where it says “Untitled” at the top of the screen (it might have a number as well) and change the title to “Mouse Maze”.

Now we need to get rid of the cat sprite. Find the sprite in the library and click the trash can to remove it.

Get the Mouse

Now we’ll get the mouse. Hover over the cat icon in the sprite library (bottom right) and select “Choose a Sprite.”

Scroll until you see Mouse1 and select that sprite.

Make Him Move

From “Events”, add the “When flag clicked” event to the sprite.

We want to constantly check if the user is pressing any buttons. Add a “forever” loop from the controls and snap it to the when flag clicked block

Our mouse needs to move in four directions: right, left, up, and down. We need to add a check for each one of those. It doesn’t matter which order we check, but we’ll start with going right.

In “controls”, find a block called “If … then” and drag it into the work area. It looks like this:

In “sensing” find a diamond shape that says “key <space> pressed?”

Drag that into the hexagonal space in the “if … then” block. the block will change shape so everything fits.

This block is checking if the player is pressing the space bar- but we want to check for the arrow key. Click the word “space” and a list of keys will pop up. Choose “right arrow.”

Now we need to tell the program what we want to happen when the right arrow gets pressed. We want two things to happen: We want the mouse to point to the right, and we want him to move in that direction. Here are the two commands to add (they are under “motion”):

Drag the entire “if then” block inside the “forever” loop.

Now when you click the flag above the stage (upper right), you can press the right arrow to move the mouse to the right!

Now do the same thing for the left, up, and down arrows. Make sure to change the number in the “point in direction” block to match the way the mouse should point. You can use the direction guide to help you.

When you are done your code should look like this:

Be careful!

Look at each of the “if… then” blocks. Notice that they are stacked on top of each other. They are not inside each other! Make sure to avoid something like this:

Part 2: Making the Maze