- Learnt28 min · who makes games, steering, two players, the grass, checkpoints
- Basic24 min · build the draft race
- Challenge 1–327 min · two drivers, the grass, honest laps
- Extrabonus · countdown and clock
Review — Whack-a-mole, finished 5 min
- Two costumes and a blue edge stopped the hammer being cheated.
- Digits made inside a
foreverloop keep up with a changing number. - A My Block lets you write a job once and ask for it by name.
Quick-fire
You are about to write the same fifteen blocks for the fourth time. What should you do?
Reveal the answer
Make a My Block. Copying is fine once; the third copy is a sign you have found something worth naming.
Today’s Topic 3 min
- Who actually makes a game
- Steering: turning, then driving forward
- Two players sharing one keyboard
- Going off the track
- Counting laps so nobody can cheat
Learning outcome
By the end of this lesson you will be able to:
- Control two sprites at once from one keyboard.
- Make a sprite turn and drive like a car.
- Count laps using checkpoints, so going backwards does not score.
Learnt — a race that works 28 min
Who makes a game?
Nobody makes a big game on their own. A game studio is a team, and each person does one job:
- Designer — decides what the game is and what the rules are
- Artist — draws the cars, the track, the menus
- Programmer — writes the code (that is you today)
- Level designer — builds the tracks and decides which is hard
- Sound engineer — engines, crashes, music
- Tester — plays it and tries to break it
In our class you do all six. When you tried to cheat your own Whack-a-mole last lesson, you were the tester.
Do people get paid for this?
Yes. A game developer in the United States earns about $50,000 a year on average. Studios make money three ways: selling the game on a shop like Steam or the App Store, selling extras inside a free game, and showing adverts.
And even if you never make a game for a living, a game is the friendliest way to learn to code — because you can see whether it worked.
Our game, on paper first
Before opening Scratch, decide what you are building. Ours is:
- One or two players
- First car to finish three laps wins
- A clock, so you can beat your own time
- A 3-2-1 countdown before the start
You need two things drawn: a car seen from above, and a track.
Steering a car
Until now your sprites moved with change x by (10). A car does not work like that. A car turns, and then it goes forward — wherever its nose is now pointing.
forever
if <key [left arrow v] pressed?> then
turn ccw (6) degrees
end
if <key [right arrow v] pressed?> then
turn cw (6) degrees
end
if <key [up arrow v] pressed?> then
move (4) steps
end
if <key [down arrow v] pressed?> then
move (-2) steps
end
end
Two players, one keyboard
Player 2 gets the same script with four different keys:
- W forward, S back
- A turn left, D turn right
Each car only ever asks about its own keys, so both players can hold keys down at the same time and neither script notices the other.
Off the track
Right now you can cut straight across the middle and win. The grass has to cost you something.
forever
if <touching color [#3FA34D]?> then
set [speed v] to (1)
else
set [speed v] to (5)
end
if <key [up arrow v] pressed?> then
move (speed) steps
end
end
(speed) how far to go.Counting laps — and the cheat
The obvious way to count a lap is the wrong one:
if <touching color [#FFFFFF]?> then
change [lap v] by (1)
end
Sit your car on the finish line and nudge it backwards and forwards. You have ten laps before anyone has finished their first corner.
The fix is the same thinking as last lesson’s hammer: the game must know it really happened. Put three checkpoints round the track and make the car collect them in order.
forever
if <touching color [#FF00A8]?> then
set [checkpoint v] to (1)
end
if <<touching color [#00D0FF]?> and <(checkpoint) = (1)>> then
set [checkpoint v] to (2)
end
if <<touching color [#FFE100]?> and <(checkpoint) = (2)>> then
set [checkpoint v] to (3)
end
if <<touching color [#FFFFFF]?> and <(checkpoint) = (3)>> then
change [lap v] by (1)
set [checkpoint v] to (0)
end
end
Basic — build the draft race 24 min
Step 1 — the track
Paint a backdrop: grass, then a wide road on top of it. Add a white finish line across the road, and three coloured lines round the rest of it.
Step 2 — the cars
Two car sprites, seen from above, nose pointing right. Shrink them until two fit side by side on the road.
Step 3 — driving
Give each car its forever loop with four key checks. Test both at once.
Step 4 — the grass
Add the speed variable and the touching color [#3FA34D]? check. Make sure the green you pick is the green in your grass — use the eyedropper.
Step 5 — laps
Add lap and checkpoint, and the four checks above. Then try to cheat it.
Step 6 — someone wins
When a lap reaches 3, say who won and stop the cars. A variable called winner holding “Red” or “Blue” is the easiest way.
The car spins instead of driving.
Your left/right blocks are moving as well as turning, or your turn is too big. Six degrees is about right; fifteen feels like a shopping trolley.
The car is always on the grass, even on the road.
The green in your block is not the green in your backdrop. Click the swatch, then the eyedropper, then click the grass itself.
The lap goes up by 5 or 6 at once.
The car is touching the line for several loops in a row. Add wait until <not <touching color [#FFFFFF]?>> after you count the lap, so it counts once per crossing.
Only one car moves.
Both cars are reading the same keys. Check player 2’s script really says W, A, S and D — it is easy to duplicate a sprite and forget to change them.
Two drivers
The deck’s mission, first half.
- Player 1 drives with ↑ ↓ ← →.
- Player 2 drives with W S A D.
- Both cars must be able to move at the same time.
- Turning and driving are separate — left and right never move the car forward.
Keep off the grass
Cutting the corner has to be a bad idea.
- On the road, the car moves 5 steps.
- On the grass, 1.
- It must work for both cars, and each car has its own speed.
Teacher note
Two speed variables, not one. A shared (speed) means red going onto the grass slows blue down too — a lovely bug to let them find rather than warn about.
An honest lap
The deck’s mission, second half — and the real work of today.
- Count each car’s laps.
- Reversing over the finish line must score nothing.
- Sitting on the line and wiggling must score nothing.
- A proper lap counts exactly once.
Teacher reveal — other ways to solve it
Checkpoints are the version this lesson teaches, but they are not the only answer, and a pupil who finds another good one has done better than following along:
- Direction: only count the line if the car’s direction is roughly right. Simple, but it fails on a track that doubles back.
- Halfway flag: one checkpoint on the far side instead of three. Enough to stop the wiggle, and much less to build.
- Timing: refuse a second lap within a few seconds of the last. It works and it is cheap — and it will one day refuse somebody’s genuinely brilliant lap, which is worth pointing out.
Countdown and clock
Make the start of the race feel like a race.
- Nobody moves until the countdown finishes: 3… 2… 1… GO!
- A clock counts up from GO until somebody wins.
- The winner’s time is shown at the end.
Summary 5 min
- Games are made by teams. Today you are the whole team.
- A car turns, then moves forward —
turn cw (15) degreesand thenmove (10) steps, in that order. That is what makes it a car and not a sprite. - Two players share one keyboard by each script only asking about its own four keys.
- A variable can be a setting, like
(speed), not just a score. - Checkpoints in order make a lap honest. Any counter that trusts one moment can be tricked.
- Checkpoint
- A place you must pass through before the next one counts.
- Two-player
- One game, two sets of controls, both live at once.
- Tester
- The person whose job is to break the game before a player does.
- Draft
- A rough first version that works. You make it good afterwards.
Hand in
Share your race and send the link to your teacher. Next lesson the track gets a menu and the cars get sound.