- Learnt28 min · momentum, steering as a number, checkpoints as a sprite
- Basic24 min · upgrade your race
- Challenge 1–327 min · momentum, the grass, five posts
- Extrabonus · three tracks
Review — where we got to 5 min
- Two cars, two sets of keys, both live at once.
- A car turns, then moves forward —
turn cw (15) degreesand thenmove (10) steps, in that order. - Checkpoints in order stop the finish line being cheated.
Quick-fire
Your car does exactly 4 steps whenever you hold up, and stops dead the instant you let go. What does that feel like?
Reveal the answer
Like a chess piece, not a car. Real cars build up speed and roll on after you stop pushing. That is today.
Today’s Topic 3 min
- Acceleration — speed that builds up
- Friction — speed that leaks away
- Steering as a number, and what a negative turn means
- Checkpoints as a sprite, placed by your own block
Learning outcome
By the end of this lesson you will be able to:
- Make a sprite that keeps moving after you let go of the key.
- Use one variable, positive or negative, to turn either way.
- Place five checkpoints with one My Block and count laps from them.
Learnt — giving the car weight 28 min
What is missing
A real car does not go from still to fast in an instant. It accelerates — it gets quicker while you keep your foot down. And when you lift off, it does not stop; it rolls, and slowly loses speed.
Your car does neither. Let’s fix both with one variable.
Step 1 — the key stops moving the car
This is the strange bit, and it is the whole idea: the up arrow no longer moves the car. It makes a number bigger.
if <key [up arrow v] pressed?> then
change [speed v] by (0.8)
end
if <key [down arrow v] pressed?> then
change [speed v] by (-0.8)
end
Step 2 — one block does all the moving
move (speed) steps
Try it. Hold up for a second, then let go. The car keeps going for ever, because nothing ever makes speed smaller again.
Step 3 — friction
Take 10% off the speed every time round the loop:
set [speed v] to ((speed) * (0.9))
Steering, the same way
Do it again with a second variable. And here is the neat part — there is only one turn block:
if <key [left arrow v] pressed?> then
change [steering v] by (-1.2)
end
if <key [right arrow v] pressed?> then
change [steering v] by (1.2)
end
turn cw (steering) degrees
set [steering v] to ((steering) * (0.85))
turn cw (-5) degrees is a turn to the left.Checkpoints, properly
Last lesson the checkpoints were colours painted on the track. That works, but it means every track you draw has to use exactly the right colours.
Better: make them a sprite, with five costumes numbered 1 to 5. Post 5 is the finish line.
Placing five clones is five near-identical jobs — so make a block:
define Post (x) (y) (number)
go to x: (x) y: (y)
switch costume to (number)
create clone of [myself v]
when flag clicked
hide
Post (145) (62) [1] :: custom
Post (145) (-62) [2] :: custom
Post (-145) (-62) [3] :: custom
Post (-145) (62) [4] :: custom
Post (0) (100) [5] :: custom
One rule for all five
Every post runs the same check:
- Am I touching the car?
- Is my number exactly one more than the last checkpoint collected?
- If yes, I am the new last checkpoint.
- And if I am number 5, that is a lap — count it and go back to 0.
when I start as a clone
show
forever
if <touching [Red car v]?> then
if <(costume [name v]) = ((P1 checkpoint) + (1))> then
set [P1 checkpoint v] to (costume [name v])
if <(P1 checkpoint) = (5)> then
change [P1 lap v] by (1)
set [P1 checkpoint v] to (0)
end
end
end
end
Why costume name and not costume number?
Either works, as long as they match. Our checkpoint sprite borrows ten costumes named “0” to “9”, so costume name “3” is the honest label and costume number would be 4 — one out, all the way along.
If you paint your own five costumes and name them 1 to 5, the number and the name agree and you can use either. Mixing them up is the single most common reason this stops working.
Basic — upgrade your race 24 min
Open your Lesson 5 race.
Step 1 — two variables per car
Make P1-Speed and P1-Steering. Set both to 0 when the flag is clicked.
Step 2 — rewrite the controls
The four key checks now only change numbers. Then, still inside the loop: turn cw (P1-Steering) degrees, move (P1-Speed) steps, then the two ×-blocks.
Step 3 — feel it
Drive it. Try 0.9, then 0.98, then 0.7 for the friction. Bigger is more slippery. Pick what you like.
Step 4 — the checkpoint sprite
New sprite, five costumes, the Post My Block, and the clone script above.
Step 5 — player 2
Duplicate the car, change the four keys, and make P2-Speed, P2-Steering, P2 checkpoint and P2 lap. Add a second check to each post for the blue car — one sprite watches both.
The car spins on the spot and never stops turning.
Your steering has no friction. Add set [steering v] to ((steering) * (0.85)) at the bottom of the loop.
The car shoots off the screen instantly.
Change speed by 0.8, not 8. And check the ×0.9 is in the loop — without it nothing ever slows down.
The lap never counts.
Nine times out of ten it is costume number against costume name. Show costume [name v] on the Stage and drive over each post to see what it really says.
Both cars share the same lap count.
The post is only checking one car, or both checks write to the same variable. Each car needs its own checkpoint and lap variables.
Give it weight
- Holding up makes the car faster and faster, up to a top speed.
- Letting go makes it roll on and slow down by itself.
- Turning has the same feel.
Grass, not a wall
The deck’s mission. Going off the track must not send you back to the start.
- On the grass, the car crawls.
- Back on the road, it picks up speed normally.
- Nothing teleports, and nothing resets.
Teacher note
Being sent back to the start is the harsher rule and the easier code, so some will have built it that way. Ask which is more fun to play. It is a design question, not a programming one, and it is the first time this course has asked one.
Five posts, two cars
- One checkpoint sprite, five clones, placed by a My Block.
- Skipping a post does nothing at all.
- Both cars are counted, separately, by the same five posts.
Teacher reveal — hiding the posts
The deck paints the checkpoints the same colour as the road, so players cannot see them. Ours are visible on purpose — a pupil debugging an invisible checkpoint is debugging blind.
Get it working visible, then hide it. Either set [ghost v] effect to (100) or paint them the road colour; both still count, because touching [edge v]? does not care what a sprite looks like.
Three tracks
Next lesson the game gets a menu, and a menu needs something to choose between. Draw three tracks.
- An easy one — wide, gentle corners.
- A hard one — narrow, twisty.
- One of your own design. A figure of eight is a good one.
Summary 5 min
- Acceleration: the key changes a number, and one
move (speed) stepsdoes the moving. - Friction: multiply by 0.9 every loop and the car coasts to a stop by itself.
- One turn block does both directions, because a negative turn goes the other way.
- Checkpoints as a sprite work on any track, and a My Block places all five in five lines.
- A post counts only if its number is one more than the last one — which is what makes a lap honest.
- Acceleration
- Speed going up while you keep pushing.
- Friction
- Speed leaking away when you stop pushing.
- Negative
- Below zero. In motion blocks it means the opposite direction.
- Clone
- A copy of a sprite made while the game runs. All five posts are one sprite.
Hand in
Share your race and send the link to your teacher — and bring three tracks next week.