Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

arrow_back Step on the Gas (Part 2 of 2)


In step 2 of this add-on, I'll show you how to program the racer to drive quickly on the grey concrete, and slowly when on the green grass.

To code this, you will use an “if-else” block. This block will end up reading: “If touching the grass, set speed to something slow. If touching anything else, set speed to something fast.” To start, click on player 1.

Select events, and drag out a "when green flag clicked" block to start this block stack.

Then, go to Control, and select a forever loop.

Inside this forever loop, I'll put an "if-else" statement which is also found in Control.

Now, program this to say: The computer can sense if a sprite is touching a color, so use a "touching color" block found in the Sensing menu to see if the sprite is on the green grass.

Click on the color in this block, then on the green color in the project to change the value of this block.

Then, click on data and select a “set speed block," and change the value to 2.

Remember, this block won’t be there if you haven't completed the previous screencast. In the “else” space in the if-else statement, place another “set speed” block. Change this value to something faster, like 7.

Your code now reads: When the flag is clicked, if the sprite is touching green, set speed to 2.

If the sprite is touching anything else, set speed to 7.

The forever loop makes sure that this if-else statement runs forever, not just once. Let's try it out!

Click the green flag to start.

to tell the computer when to run this code. Test your code by clicking the flag.

Now my player 1 sprite moves slowly when on the green grass and quickly when on the gray concrete.

You can also program this for player two.

Choose an Add-On
Change Up your Racetrack
Add a button that changes the racetrack backdrop.
Costume Change
Change what the racers look like when a key is pressed.
Step on the Gas (Part 1 of 2)
Change how fast the racers move, then make them slowdown on the grass.
Step on the Gas (Part 2 of 2)
Change how fast the racers move, then make them slowdown on the grass.
Crashing Sounds
Play a crashing sound each time the racers hit each other.
Race Fans
Program a sprite to count down to the start of the race and cheer.
Color Trail
Add a colorful trail effect to the racers.
arrow_backward Back
Next arrow_forward
  1. Choose an Add-On, and click "watch" to learn how to build it.
  2. Once you finish one Add-On, try another one below the video!