Scratch exercise 93

Velocity car

In this exercise you will add some scripts to a car to control it's direction and speed.

Complete these steps ..

 

1. Create a new game (From the top menu choose File>New).

 

2. Delete the cat sprite.

 

3. Select the stage, click the "scripts" tab and add these scripts ..

 

4. Download, save and then use the "Choose new sprite from file" button under the stage to add this image as a new sprite ..

Re-name it "Car".

 

5. Create a new variable ("For this sprite only") named "velocity", then add these scripts to the car ..

Note how we are using a green "not" operator in a repeat until loop to run the acceleration (moving) script until the space bar key is released, after which the car slows to a stop (brakes).

Also note that the maximum velocity is 9 (steps).

 

6. Use "File>Save as" to save your game. Name it "Velocity car".

 

7. You've finished, well done! Press the "B" key, or click the green flag, to start your game, and then hold down the space-bar to accelerate and move the mouse to steer the car. Can you develop this into a game?