- Learnt27 min · a lane, a finish line, and two of everything
- Basic25 min · build the race
- Challenge 1–328 min · your race, a fair one, an obvious winner
- Extrabonus · a third player
Review — where we got to 5 min
Pet Pal is finished. There are no new blocks today. You have built everything in this lesson before.
- The controller from Topic 1.6:
foreverwithif <key [d v] pressed?> theninside it. touching [Star v]?, from the Maze Escape’s exit.
Quick-fire
Two players will share one keyboard. What will go wrong first?
Reveal the answer
The hands. If both sets of keys are in one corner, the hands bump into each other. This happens with two people, and with your own two hands. The keys must be at opposite ends.
Today’s Topic 3 min
- Two sprites, two lanes and two different keys.
- A finish line sprite. The race ends when somebody reaches it.
wait until <touching [Finish v]?>as a whole script.- Why two controllers must be the same, except for the key and the lane.
Learning outcome
By the end of this lesson you will be able to:
- Build a controller for one player. Copy it for a second player.
- End a race when either player reaches the finish.
- Say why it is a bug, not a skill, if one player always wins.
Learnt — a lane, a line, and two of everything 27 min
1 · One lane first
Build half a race. One rocket, one key. If it does not work for one player, it will not work for two.
- New project, cat deleted, the Space backdrop.
- Add a rocket sprite. Name it
Rocket 1and put it atx: -200 y: 70. - Add
point in direction (90). Now the rocket always starts facing the right way. - Build the forever loop with one if in it. It listens for the D key.
- Press the flag, click the Stage once, and hold D.
when flag clicked
set size to (80) %
point in direction (90)
go to x: (-200) y: (70)
forever
if <key [d v] pressed?> then
change x by (4)
end
end
How to use this: Click the green flag, click the stage once, then hold D. One rocket, one key — half a race.
2 · The finish line
The line is a sprite. The Maze Escape asked if you reached the exit star. We ask the same question here. This time it gets a whole script of its own.
- Add a tall thin sprite at
x: 200. Paint one if you like. - Name it
Finish. - On the rocket, start a SECOND green-flag stack.
- Put
wait until <touching [Finish v]?>in it. - Under that, a sound, a message, and stop all.
when flag clicked
wait until <touching [Finish v]?>
start sound [Win v]
say [Blue wins!] for (3) seconds
stop [all v]
How to use this: Click the green flag, click the stage once, then hold D all the way to the line. Then try letting go halfway.
3 · Two of everything
The second player is a copy of the first, with just two changes. If you change anything else by mistake, the race is unfair.
- Right-click
Rocket 1in the sprite list and choose Duplicate. - Rename the copy
Rocket 2. - Change its
go to x: (-200) y: (70)toy: -70. - Change its key dropdown from
dtoright arrow. - Change the words in its say block to
Red wins! - Give it a different costume colour. Now you can tell the two apart at a glance.
when flag clicked
set size to (80) %
point in direction (90)
go to x: (-200) y: (-70)
forever
if <key [right arrow v] pressed?> then
change x by (4)
end
end
How to use this: Click the green flag, click the stage once, then hold D with one hand and → with the other. Both rockets are yours.
Basic — build the race 25 min
One rocket that works is better than two half-built ones.
Step 1 — the track
- New project, cat deleted, a backdrop you like.
- Add a tall thin sprite on the right and name it
Finish. - Give it a flag stack that puts it in place. Then it can never move by mistake.
Step 2 — the first racer
- Add your first racer sprite in the top lane.
- Build its green-flag stack: size, direction and start position.
- Build the controller loop with one key.
- Test it. Drive it all the way to the line.
Step 3 — winning
- Add the second stack with the wait-until in it.
- Put a sound, a message and a stop under it.
- Test it three times.
Step 4 — the second racer
- Duplicate the whole sprite.
- Change its lane, its key and its winning message.
- Change its colour or its costume.
- Read both controllers side by side. Check every OTHER number is the same.
Step 5 — play it
- Race yourself five times: left hand on D, right hand on the right arrow.
- Swap hands over and race five more.
- Does the same racer win every time, whichever hand drives it? Then something is not equal. Go and find it.
Neither rocket moves.
Nobody has clicked the Stage. A project only hears the keyboard after you click on it.
Both rockets move when I press one key.
The copy kept the first sprite’s key. Open its controller and change the dropdown.
One player always wins, whoever is in the seat.
Their move number is bigger, or their start x is further right. Read the two green-flag stacks side by side.
The winning message flashes and the race is still going.
stop [all v] is missing. Or the say block has no seconds on it, so it goes away straight away.
Your race, your world
Rockets in space is my idea. Make it yours.
- A backdrop that is not space.
- Two racers that suit it and are easy to tell apart.
- A finish line that looks like a finish line.
Prove it is fair
If one side always wins, the race is broken, not hard. Prove yours is fair. Write down how you proved it.
- Both lanes are the same length.
- Both racers move by the same amount.
- You raced five times. Then you swapped seats and raced five more.
- You can say what the results were.
Teacher note — swapping seats is the whole test
A pair who race ten times without swapping learn nothing: the better player wins and everybody assumes that is why. Swapping is what separates a fast player from a fast sprite, and it is the reason this mission is worth ten minutes rather than two.
Make the winner obvious
Nobody should argue about a close finish. Make the winning moment very clear.
- The winner does something the loser does not.
- You can see it from across the room, with the sound off.
- It says which player won. Not just that somebody won.
- It stays on screen long enough to read.
Teacher note — the honest photo finish
If both rockets touch the line in the same frame, both winning scripts run and the second message replaces the first. That is a real bug and the class will hit it. The fix — a variable saying whether the race has been won — is next lesson, so today the right answer is to notice it and say so, not to fix it.
Room for a third
Add a third lane and a third player. The blocks are not the hard part. The hard part is finding three keys that three pairs of hands can reach at once.
How to use this: Click the green flag, click the stage once, then try D, K and → at the same time. See how many of the three you can drive at once.
- Three lanes, evenly spaced, all the same length.
- Three keys that three people can hold at once without touching.
- You can tell all three racers apart at a glance.
- Any of the three can win. The message says which one.
Teacher notes — the duplicate trap, and the keyboard one
Duplicating a sprite copies its key. A pupil who duplicates twice and changes one dropdown ends up with two racers on the same key, which looks like one racer moving twice as fast. Make them read all three controllers out loud.
The keyboard problem is real and worth stopping on. D, K and the right arrow spread three hands across the whole keyboard. A, S and D put three children in the same six centimetres.
Some keyboards also refuse to report more than a few keys held at once. If a lane goes dead when all three players press together, that is the hardware and not the project — spreading the keys further apart usually fixes it.
Going further: next lesson nobody can start before the countdown finishes.
Summary 4 min
No new blocks today. But nobody could have built this game in week one.
- A lane is a controller that only moves one way.
- A finish line is a sprite. Reaching it is a touching question.
wait until <>makes a whole winning script out of five blocks.- Two controllers must differ in just two things: the key and the lane.
- Lane
- One player’s row of the Stage. Same length as everybody else’s.
- Finish line
- A sprite at the end of the track. Touching it wins.
- Fair
- Both players can win. Swapping seats is how you prove it.
- Duplicate
- Copying a whole sprite with its scripts. It is faster than building again, but easy to get wrong.
Next lesson: a countdown, and a race nobody can start early.