Boat Race - Scratch Projects
Boat Race - Scratch Projects
Boat Race - Scratch Projects
Boat r ace
obstacles
In this resource, you are going to learn how to make a racing game. The player uses the mouse to navigate a boat to an
Hardware
So ftware
If you need to print this project, please use the printer-friendly versio n ( https: //pro j ects.raspberrypi.o rg/en/pro j
ects/ bo at-race/print) .
You can nd the co m pleted pro j ect here ( http: //rpf.io/p/en/ bo at-race-get) .
S t ep 2 G et t ing s t ar t ed
Online: open the online starter project at rpf.io/ bo at-race-starter-o n ( http: //rpf.io/ bo at-race-starter-
o n) .
If you have a Scratch account you can make a copy by clicking Rem ix.
O ine: download the o ine starter project from rpf.io/p/en/ bo at-race-go ( http: //rpf.io/p/en/ bo at-race
If you need to download and install the Scratch o ine editor, you can nd it at rpf.io/scratcho ( http: //rpf.i
o/scratcho ).
The project includes a boat sprite, and a race course backdrop with:
The player will control the boat sprite with the mouse.
Add code to the boat sprite so that it starts in the bottom left-hand corner pointing up and then follows the
mouse pointer.
when clicked
point in direction 0
go to x: -190 y: -150
forever
move 1 steps
Test yo ur co de by clicking the green ag and moving the mouse. Does the boat sprite move towards the
mouse pointer?
What happens when the boat reaches the mouse pointer? Try it out to see what the problem is.
To stop this from happening, you need to add an if block to your code, so that the boat sprite only moves if it
is more than 5 pixels away from the mouse pointer.
when clicked
point in direction 0
go to x: -190 y: -150
forever
move 1 steps
Test your code again to check whether the problem is now xed.
S t ep 4 Cr as hing!
At the moment, the boat sprite can simply sail through the wooden barriers! You’re going to x that now.
You need two costumes for your boat sprite: one normal costume, and one for when the boat crashes.
Duplicate your boat sprite’s costume, and name one costume ‘normal’ and the other ‘hit’.
Click on your ‘hit’ costume, and use the Select tool to grab pieces of the costume and move and rotate them
when clicked
point in direction 0
go to x: -190 y: -150
forever
move 1 steps
point in direction 0
go to x: -190 y: -150
You should also add code to make sure that your boat sprite always starts out looking ‘normal’.
Test your code again. If you try to sail the boat through a wooden barrier now, the boat should crash and then
Now add another if statement to your boat sprite’s code so that the player wins when they make the boat
arrive at the yellow island.
When the boat gets to the island, the game should say ‘YEAH!’, and then it should end.
stop all
Don’t forget that this new code needs to be inside the forever loop.
Cha l l e nge !
Can you add sound e ects that play when the boat crashes or reaches the island?
Now you will add a timer to your game, so that the player has to get to the island as quickly as possible.
You can also choose a look for your timer by changing how your new variable is displayed.
Now add code blocks to your Stage so that the timer counts up until the boat reaches the island.
when clicked
set time to 0
forever
Right now the game is far too easy, so you will add some things to make it more interesting.
Now add more code blocks to your boat’s forever loop so that the boat sprite moves three extra steps when
it touches a white arrow.
move 3 steps
Test your game to see whether your new booster arrows speed up the boat.
Next you’ll add a spinning gate that the boat has to avoid.
Add a new sprite that looks like this, and call it ‘gate’:
Make sure that the colour of the gate sprite is the same as the colour of the wooden barriers.
Make sure that the centre of the gate sprite is positioned in the middle.
when clicked
forever
turn 1 degrees
Test your game again. You should now have a spinning gate that you need to stir your boat around.
Cha l l e nge !
Can you add more obstacles to your game? For example, you could add green slime to your backdrop and make
changes to the code so that the slime slows the boat down when the player lets them touch.
Can you turn your game into a race between two players? The second player will need to control their boat using
the up arrow to move forward and the left and right arrow keys to turn.
Can you create more levels by adding di erent backdrops, and can you then allow the player to choose between
levels?
S t ep 8 What next ?
Congratulations on completing the ‘Boat race’ project! Would you like to try something a little more challenging?
You could try out the Mem o ry ( https: //pro j ects.raspberrypi.o rg/en/pro j ects/m em o ry?utm _so urce=pathway&ut
Published by Rasp b er r y Pi Found at i on (ht t p s://www.r asp b er r yp i .or g) under a C r eat i ve C ommons l i cense (ht
Vi ew p r oject & l i cense on Gi t Hub (ht t p s://g i t hub.com/ Rasp b er r yPi Lear ni ng /b oat -r ace)