Raspberry_Pi_Education_Manual

Hang on a second! Every time the red touches the blue dot, “score” is changed to “score + 1”. If you are good at maths that should set the alarm bells ringing! How can something be itself plus one? Don’t worry; programmers often do this. Remember that a variable is not a number; it is a container that can store numbers. We can do a sum with the number and put the result back into the same container.

Tip...

Remember, to stop everything moving so that you can sample the colour of girl’s top with the eye-dropper tool, hit the red “stop scripts” button. If you can’t find the girl sprite, have a look in the bottom-left corner. She may have run off to hide there when you dragged your mouse to the Script tab.

To see a working example of the Prancing Pony game, open RPiScratch/Projects/prancing_pony.

Racing game

Resources: The sprite “ red_car ” and the background “ track ”. The aim of the game: A two-player game. Each player controls a racing car around a track. If the car goes off the track, it crashes. The first one over the line is the winner.

Notes:

There are five tasks to program for each car:

1. Line cars up on the starting line. 2. Set the cars in motion. 3. Crash the car if it leaves the track. 4. Declare the first car over the line as the winner. 5. Oh, yes – and the players have to be able to control the cars!

1. Moving the red car

Start off with a green-flag event. When the flag is clicked, the car to should:

n  switch to “ costume1 ” n  position itself at the coordinates x: 35 y: 130 n  point itself to the right (direction 90)

A beginner’s guide to Scratch

47

Made with FlippingBook flipbook maker