Boat Race - Scratch Projects

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Pr oj ects

Boat r ace

Create a boat-racing game in which you have to avoid

obstacles

S t ep 1 Int r oduct ion

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

island without bumping into obstacles.

What yo u w ill m ake

What yo u w ill need

Hardware

A computer capable of running Scratch 3

So ftware

Scratch 3 (either o nline ( https: //rpf.io/scratcho n) or o ine ( https: //rpf.io/scratcho ))

Dow nlo ads

Downloads can be found here ( http: //rpf.io/p/en/ bo at-race-go) .


What yo u w ill learn

Use operators to compare numbers in Scratch

Add code to detect when a sprite is touching a colour in Scratch

Use a variable to record the time in Scratch

Additio nal info rm atio n fo r educato rs

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

Open the starter project.

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

-go) , and then open it using the o ine editor.

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:

Wood that the boat sprite has to avoid

A desert island that the boat has to reach


S t ep 3 Cont r olling t he boat

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

point towards mouse-pointer

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.

This is what your code should look like:

when clicked

point in direction 0

go to x: -190 y: -150

forever

if distance to mouse-pointer > 5 then

point towards mouse-pointer

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

to make the boat look like it has crashed to pieces.


Now add code to your boat so that it crashes and breaks up when it touches any brown wooden barriers.

Here’s what your code should look like:

when clicked

point in direction 0

go to x: -190 y: -150

forever

if distance to mouse-pointer > 5 then

point towards mouse-pointer

move 1 steps

if touching color ? then

switch costume to hit

say Noooooo! for 2 seconds

switch costume to normal

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

move back to its starting position.


S t ep 5 Winning!

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.

Here’s what your new code should look like:

if touching color ? then

say YEAH! for 2 seconds

stop all

Don’t forget that this new code needs to be inside the forever loop.
Cha l l e nge !

Challenge: so und e ects

Can you add sound e ects that play when the boat crashes or reaches the island?

You could even add background music!


S t ep 6 Adding a t imer

Now you will add a timer to your game, so that the player has to get to the island as quickly as possible.

Add a new variable called time to your Stage.

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.

Here’s what your new code should look like:

when clicked

set time to 0

forever

wait 0.1 seconds

change time by 0.1


Test out your game and see how quickly you can get the boat to the island!
S t ep 7 O bs t acles and boos t er s

Right now the game is far too easy, so you will add some things to make it more interesting.

First, you’ll add some boosters to speed up the boat.

Edit your Stage backdrop by adding in some white booster arrows.

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.

if touching color ? then

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.

Add code to your gate sprite to make it spin slowly forever.

Here’s what your new code should look like:

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 !

Challenge: im proving yo ur gam e

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.

You could add a moving obstacle, for example a log or a shark!

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

m _m edium =w hatnext&utm _cam paign=pro j ects) project.

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

t p s://cr eat i vecommons.or g /l i censes/by-sa/4.0/).

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)

You might also like