- Learnt28 min · escapes, lives, and ending the round
- Basic24 min · the finished game
- Challenge 1–327 min · harder, a lasting best, spiky bubbles
- Extrabonus · ship it
Review — the arc so far 5 min
create clone of [myself v], a clone script, anddelete this clonefor every one of them.- Sprite-only variables give each clone its own speed, size and worth.
when this sprite clickedlands on the clone you hit.
Quick-fire
Your popping game runs for twenty-six bubbles and then stops. It does not matter how well you play. What is missing?
Reveal the answer
A way to lose. A game needs a cost for failing. It needs an ending that depends on how you played. Both of those come from the bubble that gets away.
Today’s Topic 3 min
- A clone doing something on its way out, not just vanishing
lives, and why taking one away needs a guardrepeat untilas the spawner’s loop, so the round ends by itself- A game that gets harder, and a best score that lasts after the green flag
Learning outcome
By the end of this lesson you will be able to:
- Make a round end because of how the player played, not after a set number.
- Make a game get harder over time, with two blocks.
- Keep a best score across several rounds.
Learnt — escaping, and losing 28 min
1 · The clone reports on its way out
Up to now, a bubble reaching the surface just deleted itself. But only that clone knows it got away. So the counting belongs there:
when I start as a clone
show
repeat until <(y position) > (165)>
change y by (speed)
end
change [escaped v] by (1)
delete this clone
How to use this: Click the green flag and pop some but not all. One counter is for you, one is for the bubbles.
2 · Lives
Turn the escape counter into a cost. lives is shared, because there is one player. It starts at 3:
repeat until <(y position) > (165)>
change y by (speed)
end
if <(lives) > (0)> then
change [lives v] by (-1)
end
delete this clone
if is not optional. Read on.3 · A round that ends itself
The spawner has been using repeat (26). So the round lasts the same time however you play. Swap the loop:
repeat (26)
go to x: (pick random (-175) to (175)) y: (-170)
create clone of [myself v]
wait (0.3) seconds
end
repeat until <(lives) = (0)>
go to x: (pick random (-175) to (175)) y: (-170)
create clone of [myself v]
wait (0.3) seconds
end
One word changed, and now the game depends on the player. After the loop, wait a moment for the last clones to clear. Then show the card.
How to use this: Click the green flag and let three bubbles escape on purpose. The spawner stops on its own.
Basic — the finished game 24 min
Open last lesson’s popping game. Make four changes, and it is a real game.
Step 1 — lives
- Make
lives, for all sprites, and show it. - Set it to 3 under the green flag, before anything else.
Step 2 — escaping costs
- In the clone script, after the rise loop, add
if <(lives) > (0)> then. - Inside it:
change [lives v] by (-1). - Leave
delete this clonebelow the whole thing.
Step 3 — the round ends itself
- Swap the spawner’s
repeat (26)forrepeat until <(lives) = (0)>. - Run it. Play badly on purpose and watch it stop.
Step 4 — the game-over card
- After the loop, wait about a second for the last bubbles to clear.
- Bring the original to the middle, set it large,
showit. - Say the totals, then say
Game over., thenhide.
when flag clicked
hide
set [lives v] to (3)
set [score v] to (0)
set [popped v] to (0)
repeat until <(lives) = (0)>
go to x: (pick random (-175) to (175)) y: (-170)
set [my size v] to (pick random (20) to (62))
set [speed v] to (round ((10) - ((my size) / (10))))
set [worth v] to (round ((8) - ((my size) / (10))))
switch costume to (pick random (1) to (5))
create clone of [myself v]
wait (0.4) seconds
end
wait (1) seconds
go to x: (0) y: (0)
set size to (60) %
show
say (join [Popped ] (join (popped) (join [ for ] (score)))) for (2.5) seconds
say [Game over.] for (3) seconds
hide
How to use this: Click the green flag and play properly. Let three bubbles past and the game ends.
No bubbles appear at all.
lives is 0 when the loop starts. The set [lives v] to (3) is missing, or it is below the loop.
Lives goes to −3 and the card is late.
The guard is missing. Some bubbles were still rising when the round ended. They are taking lives they should not.
The game never ends, however many escape.
The “take a life away” block is in the click script instead of after the rise loop. So only popping costs you lives. That is the opposite of the rule.
The card never appears.
There is a forever loop where a repeat until belongs. Or there is a stop [all v] before the card.
The card appears while bubbles are still rising.
The wait after the loop is too short. A second or two is enough for the slowest bubble to reach the surface.
It gets harder
A flat game is boring. Make the bubbles come faster the longer you survive.
- A
gapvariable used by the wait, instead of a fixed number. - Every sixth bubble, the gap shrinks by a fifth.
- The gap is on screen, so you can watch the game speed up.
How to use this: Click the green flag and survive as long as you can. Watch the gap box shrink.
Teacher reveal — every sixth one
change [made v] by (1)
if <((made) mod (6)) = (0)> then
set [gap v] to ((gap) * (0.8))
end
wait (gap) seconds
mod from Lesson 3-2, doing real work: “is this a multiple of six?”. Multiplying by 0.8 rather than subtracting keeps the gap positive for ever, which subtracting would not.
A best that lasts
Play three rounds without touching the green flag. Keep the highest score from all of them.
- A key starts a round, not the flag.
scoreresets each round.bestnever does.- The game says so when you get a new best.
How to use this: Click the green flag, then press G several times. Watch best hold while score changes.
best.Teacher reveal — where the reset goes
when flag clicked
set [best v] to (0)
when [g v] key pressed
set [score v] to (0)
Two hats, and the whole idea is which one holds which reset. Same shape as the Line Follower’s lap record and the Quiz Master’s best — say so, because a pupil who spots the repeat is generalising.
Spiky bubbles
Some bubbles must not be popped. About one in four is orange and spiky. Clicking it costs a life.
- A sprite-only
spiky, 1 or 0, decided before the clone is made. - A spiky bubble is a clearly different colour.
- Clicking a spiky one loses a life. Clicking a normal one scores.
- A count of how many mistakes you made.
How to use this: Click the green flag and pop only the blue ones. The orange ones bite.
Teacher reveal — the click branches on the clone’s own kind
when this sprite clicked
if <(spiky) = (1)> then
change [lives v] by (-1)
change [spiky popped v] by (1)
else
change [score v] by (1)
end
delete this clone
If spiky is shared, every click is judged by the newest bubble’s kind and the game becomes random. It is the same bug as Lesson 3-19’s shared worth, and by now they should predict it before you run it.
Ship it
Put the whole arc into one project. Make it good enough to give to somebody else to play.
- A title before the first bubble.
- Three lives, and a round that ends itself.
- Sizes, speeds and worths picked at random for each bubble.
- A game that gets harder, golden bubbles, and a burst you can see.
- A score card, and a best that survives the round.
How to use this: Click the green flag, wait for the title, and play. Golden ones are worth twelve.
Teacher note
Worth counting the blocks with them. The shipped game is not much bigger than the Lesson 3-17 stream — almost everything added was a variable with the right scope, not more code. That is the message of the whole arc.
Summary 5 min
- A clone can act on its way out. The clone itself counts the escape.
repeat until <(lives) = (0)>makes the round last as long as the player does.- Guard the “take a life away” block with
if <(lives) > (0)> then. If not, bubbles still rising take lives you do not have. - Multiply a gap variable by 0.8, and the game gets harder. It takes two blocks.
bestresets under the flag.scoreresets each round.
- Escape
- A bubble reaching the surface unpopped.
- Guard
- An
ifthat stops a change happening when it should not. - Difficulty curve
- A game getting harder the longer it lasts.
- Game over card
- The original sprite reappearing to report the run.
Hand in
Save your finished game. You have finished the clones arc: one sprite, three hundred bubbles, and every one of them with its own values.