Operation Manual

A beginner’s guide to Scratch
49
The changes you need to make to your code for the purple car are:
The purple car should line up next to the red car at x: 30 y: 115.
You should also use the “x” key to turn the car to the right and the “z” key to turn
the car to the left.
To see a finished example of this game, open
RPiScratch/Projects/racing_game_v1.
Over to you
TASK: Add the sound of racing cars to enhance the game. You’ll need to record
or create your own sound file.
TASK: Try to make these improvements to the racing game:
In the racing game you just created, the car says “I win!” when it hits the line. But
the speech bubble is gone so fast, it’s hard to read. However, if we change the
script so that the speech bubble stays on screen for, say, 2 seconds, then there’s
a chance that the second car will also hit the finish line in that time and also say
“I win!”. Then we wouldn’t know who had really won.
Try and create a new version of the game, saving it as something like
“racing_game_v2”, this time causing the losing car to stop in its tracks the moment
the winner crosses the finish line. To do this, you’ll need to use a variable.
Call this new variable something like “have_winner. The default value of
“have_winner” should be “0”. Whenever either car wins, by touching the white
finish line, it should set the value of “have_winner” to “1. This should be the
trigger for both cars to stop moving.
Finally, instead of having the cars crash when they hit the grass, try and make
them slow down, so that the player has a chance to get them back onto the track.
To see a finished example of this game, open
RPiScratch/Projects/racing_game_v2.
Notes:
Tip...
When you are
creating a game,
don’t be over-
ambitious at the
beginning.
Program your
basic idea and
make sure that it
works. Then
develop your
game bit by bit,
adding new
characters,
events and levels.
It is a good idea
to save each new
version with a
different number,
so that you can
keep track of the
changes that
you have made.
You may get stuck
and want to
go back to a
previous version
of your game.