- 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 lesson 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 if it got past. The hare cannot see behind itself, just like you.
Today’s Topic 3 min
- A score that counts the rocks you cleared, not the seconds you lasted.
- Three lives. A hit costs just 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 when a rock is safely past.
- Take one life for one hit. 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 gives you a point when it reaches the left edge without a hit. The point goes on the line after the loop. It cannot go anywhere else.
- 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, find the
repeat (60). After it, and before the delete, addchange [score v] by (1). - Play it. Every rock that goes by is worth one point.
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
Lives is a second variable. The rock takes one life when it hits. Then it deletes itself. So one rock can only cost you one life.
- 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. Watch the number go down.
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 just a smaller number. It is the end. The rock checks for it. Then it 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) sticks words onto a number. The player reads a sentence, not just 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 your project from last lesson. You add everything today to it.
Step 1 — the two variables
- Make
scoreandlives. Show both on the Stage. - Drag their boxes to a corner where the runner never goes.
- Set both of them on the flag. Then every game starts the same way.
Step 2 — scoring
- Add the point after the clone’s loop.
- Play for twenty seconds without hopping. Check the number goes up.
Step 3 — losing a life
- Change the touching if. Now it costs a life, and does not end the game.
- Check the clone is still deleted.
- Take three hits on purpose. Lives should go down by one each time.
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.
- Does every game end under 5? Then the rocks are too fast or too close together.
- Do you never lose? Then they are too slow.
One rock takes all three lives at once.
delete this clone is missing from inside the if. So the rock still touches you the next time round the loop.
The score keeps going up after the game has ended.
Rocks on their way are still finishing their loops. stop [all v] stops them. Check that it really runs.
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 tests the wrong variable. Or it sits outside the if that took the life.
Not every rock is worth the same
Some rocks are easy to hop. Some nearly get you. The hard ones should be worth more.
- Two sizes of obstacle. 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
Right now, a life goes without a sound. A player looking at the runner does not notice.
- Something happens to the runner that you can see.
- It lasts long enough to notice. It is 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 ending.
- It says how many rocks were cleared.
- It says one thing for a good run, and another for a bad one.
- It stays on screen long enough to 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. But three hearts that go out one at a time feel like a real game. Build the hearts.
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. The right one goes each time.
- They all come back when the flag is pressed.
- You can hide the
livesvariable, 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 lesson. Now it is a game you can get good at.
- The rock scores the point. Only the rock knows it got past.
- One hit costs one life. The delete makes sure of that.
- Zero lives is an ending. It gets its own broadcast.
- The stop is the last block on the game-over stack. Never the first.
- Score
- A count of what the player did well. Set it 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
- Sticks words onto a number, so a score reads as a sentence.
Next lesson: it gets faster. There is something to collect. Standing still stops working.