- Learnt27 min · a score, three lives, a game over
- Basic25 min · build the scoring
- Challenge 1–327 min · points worth more, a visible hit, a proper ending
- Extrabonus · lives you can count without reading
Review — where we got to 5 min
Last week you built a run: a hop, rocks crossing the Stage, and an ouch.
- The rock is a clone. It goes to
x: 240, walks left, and deletes itself. - The rock asks
touching [Hare v]?inside its own loop.
Quick-fire
Which sprite should count the score — the runner, or the rock?
Reveal the answer
The rock. Only the rock knows whether it got past. The hare cannot see behind itself any more than you can.
Today’s Topic 3 min
- A score that counts the rocks you cleared, not the seconds you survived
- Three lives, and a hit that costs exactly one of them
if <(lives) = (0)> thenas the end of a game- Why the ending needs its own broadcast
Learning outcome
By the end of this lesson you will be able to:
- Add a point at the moment a rock is safely past.
- Take one life for one hit, and no more than one.
- End the game at zero and show the player their score.
Learnt — a score, three lives, a game over 27 min
1 · A point for getting past
A rock earns you a point by reaching the left edge in one piece. That is the line after the loop, and it is the only place it can go.
- Make a variable called
score. Tick its box so it shows on the Stage. - On the rock’s flag stack, add
set [score v] to (0). - In the clone stack, after the
repeat (60)and before the delete, addchange [score v] by (1). - Play it. Every rock that goes by is worth one.
when I start as a clone
go to x: (240) y: (-125)
show
repeat (60)
change x by (-8)
end
change [score v] by (1)
delete this clone
How to use this: Click the green flag and watch the score box. Nothing is in the way, so every rock that crosses is worth a point.
2 · Three lives
A life is a second variable. The rock takes one when it hits, then removes itself, so one rock can only ever cost you one.
- Make a second variable called
livesand show it too. - On the flag,
set [lives v] to (3). - In the touching if, replace the ouch broadcast with
change [lives v] by (-1). - Keep
delete this cloneright underneath it. - Play it. Get hit on purpose three times and watch the number fall.
repeat (60)
change x by (-8)
if <touching [Hare v]?> then
start sound [Boing v]
change [lives v] by (-1)
delete this clone
end
end
How to use this: Click the green flag, click the stage once, then press the space bar to hop. Stand still on purpose and watch lives fall.
3 · What zero means
Zero lives is not a smaller number. It is the end. The rock notices it, and tells everybody with a broadcast.
- Under
change [lives v] by (-1), addif <(lives) = (0)> then. - Inside that if,
broadcast [game over v]. - On the hare, add a
when I receive [game over v]stack. - Say the score, wait, then stop all.
- Play a whole game until it ends by itself.
when I receive [game over v]
say (join [Game over. Rocks cleared: ] (score)) for (3) seconds
stop [all v]
join [Cleared: ] (score) glues words to a number, so the player reads a sentence and not a stray 11.How to use this: Click the green flag, click the stage once, then press the space bar to hop. Miss three rocks and the game ends by itself.
Basic — build the scoring 25 min
Open last week’s project. Everything today is added to it.
Step 1 — the two variables
- Make
scoreandlives. Show both on the Stage. - Drag their monitors to a corner where the runner never goes.
- Set both of them on the flag. Every game starts the same way.
Step 2 — scoring
- Add the point after the clone’s loop.
- Play for twenty seconds without hopping and check the number climbs.
Step 3 — losing a life
- Change the touching if so it costs a life instead of ending the game.
- Check the deleting still happens.
- Take three hits on purpose. It should take exactly three.
Step 4 — the ending
- Add the zero question and the broadcast.
- Build the receiving stack on the runner.
- Play three full games.
Step 5 — make it fair
- Write down the score you got each time.
- If every game ends under 5, the rocks are too fast or too close together.
- If you never lose, they are too slow.
One rock takes all three lives at once.
delete this clone is missing from inside the if, so the rock is still touching you on the next time round the loop.
The score keeps going up after the game has ended.
Rocks already on their way are still finishing their loops. stop [all v] is what stops them, so check it is really running.
The score starts at last game’s number.
set [score v] to (0) is missing from the flag stack. Change is not the same as set.
Lives goes to −1 and the game carries on.
The zero question is testing the wrong variable, or it sits outside the if that took the life.
Not every rock is worth the same
A rock you barely have to move for should not pay as well as one that nearly gets you.
- Two sizes of obstacle, and you can tell them apart at a glance.
- The harder one is worth more.
- The score still starts at zero every game.
Make a hit feel like a hit
At the moment a life vanishes silently. A player looking at the runner misses it completely.
- Something happens to the runner that you can see.
- It lasts long enough to notice and short enough not to annoy.
- The runner goes back to normal afterwards.
- It works on the third hit as well as the first.
Teacher note — the effect that never gets cleared
A ghost effect turned on during a hit and never turned off leaves the runner half invisible for the rest of the game. Look for clear graphic effects on the flag stack — it is the fix, and pupils rarely think of it until it happens.
An ending worth reading
Right now the game ends with one line and a stop. Give the player a proper end of the run.
- It says how many rocks were cleared.
- It says something different for a good run and a bad one.
- It stays on screen long enough to be read out loud.
- It tells the player how to start again.
Teacher note — where the two endings come from
if <(score) > (10)> then with an else on the game-over stack is all it takes, and if / else is Topic 1.7. The number in it should be one the pupil has actually reached, not one they hope for.
Lives you can count without reading
A number in the corner is fine. Three hearts that go out one at a time is a game. Build the second one.
How to use this: Click the green flag and watch the three hearts along the top. One goes out every three seconds — nothing to press.
- Three hearts on the Stage at the start of every game.
- One goes when a life goes, and the right one goes each time.
- They all come back when the flag is pressed.
- The
livesvariable can be hidden and the game still makes sense.
Teacher notes — three sprites or three clones
Both answers are right. Three separate sprites, each hiding when lives drops below its own number, is the one most pupils find, and it is honest work.
One heart making three clones is neater and much harder, because each clone has to know which of the three it is. A pupil who tries it and fails has still learnt the more useful thing.
Going further: next lesson the run gets faster the longer you last, so the hearts start to matter.
Summary 4 min
The same run as last week, and now it is a game you can be good at.
- The rock scores the point, because only the rock knows it got past.
- One hit costs one life, and the delete is what makes that true.
- Zero lives is an ending, and it gets its own broadcast.
- The last thing on the game-over stack is the stop, never the first.
- Score
- A count of what the player achieved. Set to 0 at the start of every game.
- Lives
- How many mistakes are left. One hit, one life.
- Game over
- The broadcast that ends the run and shows the score.
- join
- Glues words onto a number so a score reads as a sentence.
Next lesson: it speeds up, there is something worth collecting, and standing still stops working.