- Learnt28 min · a drum, a flag, bombs and lives
- Basic24 min · make it march and fight back
- Challenge 1–327 min · in step, legs, three lives
- Extrabonus · shields that wear away
Review — the laser 5 min
(laser ready)is a switch: 1 means fire, 0 means wait.- The invader notices the hit and tells the laser with a broadcast.
(((6) - (my row)) * (10))makes the back row pay the most.- We count invaders up as they are built and down as they are hit.
Quick-fire
Forty invaders must all take one step at exactly the same moment. What can reach all forty at once?
Reveal the answer
A broadcast. Every clone runs its own copy of when I receive [march v], so one message moves the whole army.
Today’s Topic 3 min
- A drumbeat: one broadcast moves forty clones
- A flag: any invader can tell the whole army to turn
- Bombs from a random invader
- Three lives
Learning outcome
By the end of this lesson you will be able to:
- Move many clones in step with one broadcast.
- Use a flag variable so one clone can change what all of them do.
- Pick one clone at random by its row and column.
Learnt — forty invaders, one beat 28 min
1 · The wrong way first
The first idea is to let every invader march by itself. Each one gets its own direction and turns when it reaches the edge. Watch what happens.
when I start as a clone
switch costume to (my row)
set [my direction v] to (1)
show
forever
wait (0.3) seconds
change x by ((6) * (my direction))
if <<(x position) > (215)> or <(x position) < (-215)>> then
set [my direction v] to ((0) - (my direction))
change y by (-16)
end
end
my direction is For this sprite only. Every invader decides alone.How to use this: Click the green flag and watch. Nothing to press — see what happens when the first invaders reach the edge.
An army must turn together. So one invader reaching the edge has to turn everybody. That needs two new things: a drum, and a flag.
2 · The drum
The Stage keeps the beat. Every half second it broadcasts march. Every invader hears it and takes one step.
forever
wait (0.5) seconds
broadcast [march v] and wait
end
when I receive [march v]
change x by ((step) * (army direction))
(step)is how far one beat moves. We use 6.(army direction)is 1 for right and −1 for left. Six times −1 is −6: a step left.
3 · The flag
A flag is a variable that says “something happened”. Ours is (hit edge). It starts at 0.
- After its step, each invader checks: am I past 215, or past −215?
- If so, it sets
(hit edge)to 1. It does not turn itself. - After the beat, the Stage looks at the flag. If it is 1, the Stage flips
(army direction), broadcastsdrop, and lowers the flag.
when I receive [army ready v]
set [army direction v] to (1)
set [hit edge v] to (0)
forever
wait (0.5) seconds
broadcast [march v] and wait
if <(hit edge) = (1)> then
set [army direction v] to ((0) - (army direction))
broadcast [drop v] and wait
set [hit edge v] to (0)
end
end
when I receive [march v]
if <(my row) > (0)> then
change x by ((step) * (army direction))
if <<(x position) > (215)> or <(x position) < (-215)>> then
set [hit edge v] to (1)
end
end
when I receive [drop v]
change y by (-16)
The builder gets two lines at the very end:
when flag clicked
hide
set [invaders left v] to (0)
set [my row v] to (1)
repeat (5)
set [my column v] to (1)
repeat (8)
go to x: (((my column) * (40)) - (180)) y: ((172) - ((my row) * (32)))
create clone of [myself v]
change [invaders left v] by (1)
change [my column v] by (1)
end
change [my row v] by (1)
end
set [my row v] to (0)
broadcast [army ready v]
when flag clicked
set [step v] to (6)
How to use this: Click the green flag and watch. Nothing to press — the army marches right, turns at the edge and drops, all together.
4 · Bombs
The army fires back. Each beat, the Stage picks a random row and a random column. The invader standing on that spot drops a bomb. If that spot is empty, nobody fires.
- Make
fire row,fire column,bomb xandbomb y, all For all sprites. - In the Stage’s loop, before the march:
set [fire row v] to (pick random (1) to (5))and the same for the column, 1 to 8. - Give the Invader a second march stack that checks: is it me?
- Paint a small Bomb sprite, and give it a clone stack that falls.
when I receive [march v]
if <<(my row) = (fire row)> and <(my column) = (fire column)>> then
set [bomb x v] to (x position)
set [bomb y v] to (y position)
create clone of [Bomb v]
end
when flag clicked
hide
when I start as a clone
go to x: (bomb x) y: (bomb y)
show
repeat until <(y position) < (-170)>
change y by (-6)
if <touching [Ship v]?> then
broadcast [ship hit v]
delete this clone
end
end
delete this clone
5 · Three lives
- Make
lives. On the Stage’s flag stack,set [lives v] to (3). - On the Ship,
when I receive [ship hit v]: lose a life, then flash. - At no lives left,
broadcast [game over v]. - Paint a Banner sprite with a big GAME OVER costume. It shows itself and stops everything.
- Add
showto the Ship’s flag stack. A game can end while the ship is flashing — hidden.
when I receive [ship hit v]
change [lives v] by (-1)
if <(lives) < (1)> then
broadcast [game over v]
end
repeat (3)
hide
wait (0.1) seconds
show
wait (0.1) seconds
end
when flag clicked
hide
go to x: (0) y: (40)
when I receive [game over v]
go to [front v] layer
show
stop [all v]
stop [all v] wipes speech bubbles and clones, so a costume is the only message that stays.
when flag clicked
set [lives v] to (3)
set [step v] to (6)
How to use this: Click the green flag, click the stage once, then hold ← or → to dodge the bombs. You cannot fire in this one.
Basic — make it march and fight back 24 min
Open last week’s game. Work in this order and test after every step.
Step 1 — the drum
- Make
step,army directionandhit edge, For all sprites. - Add the two lines to the end of the builder.
- Build the Stage’s flag stack and its drum.
- Give the Invader its march and drop stacks.
- Press the flag. Watch one whole edge-turn-drop.
Step 2 — the bombs
- Paint the Bomb and make the four new variables.
- Add the two random picks to the drum.
- Add the Invader’s second march stack and the Bomb’s stacks.
- Sit still under the army. A bomb should reach you within a few seconds.
Step 3 — the lives
- Add lives, the Ship’s hit stack and the Banner.
- Lose three lives on purpose. GAME OVER must appear.
- Press the flag. The ship must be back, with three lives.
The army walks off the edge and never turns.
Nothing raises the flag, or the Stage never lowers it. Show the hit edge monitor and watch it: it should flash to 1 and straight back to 0.
The army turns much too early.
The original is marching too. Check the builder ends with set [my row v] to (0), and the march stack has if <(my row) > (0)> then.
The army shakes left and right at the edge.
set [hit edge v] to (0) is missing, so the Stage turns the army on every beat.
Bombs all start in the middle of the Stage.
The bomb’s clone stack is missing go to x: (bomb x) y: (bomb y), so every bomb starts where the hidden Bomb sprite stands.
One bomb takes all three lives.
The bomb does not delete itself after broadcast [ship hit v], so it keeps touching the ship.
In step
- The whole army marches together, one step a beat.
- When any invader reaches an edge, all of them turn.
- All of them drop together.
- The columns stay straight, however long it runs.
Teacher note — show the flag
Ask pupils to tick the hit edge monitor. It is 1 for only a moment. A pupil who sees it flash has understood that the flag is a message, not a state: “this happened”, read once, then cleared.
Legs
Every invader has a second costume with its legs out. Use it.
- On every beat, the whole army switches legs together.
- Each row keeps its own look while its legs move.
- The legs match across the whole army — all in, or all out.
Teacher reveal — one number for the whole army
Put costumes 1–5 in row order with legs in, then 6–10 in the same order with legs out. A variable frame flips between 0 and 5 on every beat. Each invader adds it to its row.
set [frame v] to ((5) - (frame))
switch costume to ((my row) + (frame))
next costume is the tempting wrong answer: row 1’s legs-out costume would step on into row 2’s costume.
Three lives
- Bombs fall from random invaders — never from an empty spot.
- A bomb costs one life, and the ship flashes.
- At no lives left, GAME OVER shows and everything stops.
- The flag gives back three lives, a visible ship and a full army.
Teacher reveal — why fewer invaders means fewer bombs
The Stage picks one of forty spots. With twenty invaders left, half the picks land on empty spots, so half the beats drop nothing. Pupils often notice before they can say why. Ask them: “how many spots are there, and how many are still full?”
How to use this: Click the green flag, click the stage once, then hold ← or → to move and the space bar to fire. You have three lives.
Shields that wear away
Bring back the shields from Lesson 2-41’s Extra. If you did not build them then, build them now. This time, they take damage.
How to use this: Click the green flag, click the stage once, then hold ← or → to move and the space bar to fire. Fire into a shield to wear it away.
Teacher notes — who notices, again
The same question as the laser hit: two sprites touch, who notices? Here both do. The brick waits a tiny moment before it goes, so the bomb or laser has time to see it too.
when I start as a clone
show
wait until <<touching [Bomb v]?> or <touching [Laser v]?>>
wait (0.05) seconds
delete this clone
The bomb gets one more check in its loop, and the laser one more reason to stop:
if <touching [Shield v]?> then
delete this clone
end
repeat until <<(y position) > (170)> or <touching [Shield v]?>>
change y by (10)
end
Summary 5 min
- One broadcast reaches every clone. A drum on the Stage moves the whole army.
- The hidden original hears it too. Give it row 0 and leave it out.
- A flag is a message: any clone raises it, the Stage reads it and lowers it.
broadcast [march v] and waitlets everyone answer before the Stage looks.- Pick a random row and column, and only the clone on that spot acts.
- Beat
- One tick of the drum. Everything that marches moves once.
- Flag
- A variable that says “this happened”. Raised, read, then lowered.
- In step
- Moving at the same moment by the same amount.
- Broadcast and wait
- Send a message, and carry on only when everyone has finished with it.
Next lesson: the army speeds up as it thins, waves come one after another, and the game gets a real ending.