Pike Sprites

Basics: Obstacles

Watch the movie
Step 1. Make sure you know the basics
Step 2. Create the platform
Step 3. Make the cat walk
Step 4. Create the sensor
Step 5. Detect a touch
Step 6. Make the cat turn
Extra Credit!

Watch the movie

In the movie below, the cat walks across the screen automatically. When the cat reaches the each end, he turns and walks in the opposite direction. No keys are pressed! Can you figure out how it’s done?

Step 1. Make sure you know the basics

  • If you don’t know how to how to make the cat move across the screen, go to Getting Started: Run to learn the basics.
  • Be sure to name your cat sprite cat

Then come back here!

Step 2. Create the platform

For this project, you must create one additional sprite: the platform.

The movie below shows how to create the platform. Make sure your computer’s sound is turned on so you can hear the narration.

Step 3. Make the cat walk

Let’s return to the cat for a moment.

Can you position the cat at the bottom of the screen, facing right? You’ll need the commands below (change the numbers where necessary).

Now, can you make the cat walk across the screen as in the movie below? Don’t worry if he runs past the right end wall and off the screen! We’ll fix that later.

Hint!

  • Use the commands below to make the cat walk (change the numbers where necessary).

Step 4. Create the sensor

In this project, there’s a sensor that tells the cat when he reaches the end walls. The sensor is a vertical line that always moves with the cat. You can watch the movie below to see how to create a sensor for the right side of the cat.

After you’ve created the right-side sensor, you must make it invisible. Can you figure out how to use the commands below to do so?

Hint! You will need to change the number in the change ghost effect command.

Step 5. Detect a touch

When the cat reaches the wall at the right end, we’d like him to turn automatically. To do so, we’ll ask the hit right sensor to send a message to the cat whenever it touches the wall.

To begin, let’s go to the script for the hit right sensor. We’ll create a variable called hit right. A variable is a hidden container that can hold a number. We’ll tell the sensor to put the number 1 into the variable hit right whenever the hit right sensor touches the wall.

You can watch the movie below to learn how to create the variable hit right.

Now that you’ve created hit right, let’s set its value to 0 at the beginning of the hit right sensor’s script. Add the command below:

The sensor should always travel with the cat. And when the sensor touches the platform, the value of hit right should change to 1. When the sensor is not touching the platform, the value of hit right should be 0. In your hit right sensor’s script, can you add the following commands and assemble them to do these tasks?

Step 6. Make the cat turn

Here’s the final step! You must make the cat turn whenever the variable hit right contains the number 1 (whenever, in other words, the cat has hit the wall). To do so, you need a new kind of command — an operator that can determine if a variable like hit right equals 1. Here’s the command you need:

And here’s what the command should look like in your script:

All together, you’ll need to add the following commands to the cat’s script in order to make the cat move and turn when it hits the right end. What does the turn 180 degrees command do? What happens if you omit move 4 steps?

Extra Credit!

Can you add a left sensor to make the cat turn when it reaches the left end of the platform?

Good luck!

Return to Games Page | Return to Home Page

Copyright 2011
The Pike School