- Learnt27 min · a grid of clones that know their place, and a ship
- Basic25 min · build the army and the ship
- Challenge 1–327 min · five looks, two edges, your own army
- Extrabonus · shields
Review — the Penalty Shootout 5 min
- A power meter is a number that climbs and falls in a loop.
- A key press freezes it. The number at that moment is the power.
- The keeper chose a side by itself, with
pick random (1) to (3). - The best streak stayed, because the green flag never reset it.
Quick-fire
You need forty invaders on the screen. How many sprites do you make?
Reveal the answer
One. Forty clones of it, made by loops. In Level 1’s Paddle Bounce one loop made a row. Today two loops make rows of rows.
Today’s Topic 3 min
- A repeat inside a repeat
- Clones that know their own row and column
- A costume chosen by the row
- A ship that stays on the Stage
Learning outcome
By the end of this lesson you will be able to:
- Build a grid of clones with two loops, one inside the other.
- Give every clone its own row and column number.
- Keep a sprite on the Stage with two comparisons.
Learnt — one sprite, forty invaders 27 min
1 · A repeat inside a repeat
In Level 1 you built one row of targets with one loop. An army is five rows. So we put the row loop inside a second loop.
Two counters keep track of where we are:
(my row)counts the rows, 1 to 5.(my column)counts along a row, 1 to 8.
Every invader’s place comes from those two numbers. Column times 40 gives the x. Row times 32 gives the y.
| Column | x | Row | y |
|---|---|---|---|
| 1 | 40 − 180 = −140 | 1 | 172 − 32 = 140 |
| 2 | 80 − 180 = −100 | 2 | 172 − 64 = 108 |
| … | 40 more each time | … | 32 lower each time |
| 8 | 320 − 180 = 140 | 5 | 172 − 160 = 12 |
- Make a sprite called Invader. Give it five costumes, one per row.
- Open Variables. Make
my rowand pick For this sprite only. Do the same formy column. - On the flag:
hide, thenset [my row v] to (1). - Add
repeat (5). Inside it,set [my column v] to (1)and arepeat (8). - Inside the small loop: the
go to x: () y: ()with the two sums,create clone of [myself v], andchange [my column v] by (1). - Under the small loop, still inside the big one:
change [my row v] by (1).
when flag clicked
hide
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 [my column v] by (1)
end
change [my row v] by (1)
end
Each clone only has to pick its look and appear:
when I start as a clone
switch costume to (my row)
show
How to use this: Click the green flag and watch. Nothing to press — the army builds itself one invader at a time.
2 · Each clone keeps its own numbers
This is the clever part. A clone is born as a copy of the original — its variables too. So a clone made at row 2, column 5 keeps a 2 and a 5 for ever.
- Add
when this sprite clickedto the Invader. - Under it:
say (join [row ] (my row)) for (1) seconds. - Then
say (join [column ] (my column)) for (1) seconds. - Press the flag. Click invaders all over the army.
when this sprite clicked
say (join [row ] (my row)) for (1) seconds
say (join [column ] (my column)) for (1) seconds
How to use this: Click the green flag and wait for the army. Then click any invader: it says its row, then its column.
How to use this: Click the green flag and wait for the army. Then click any invader: every one says row 6, column 9.
3 · The ship
The ship slides along the bottom. The arrow keys move it. Two comparisons stop it at the edges.
- Add the Rocketship sprite from the library. Set its size to
30. - On the flag:
go to x: (0) y: (-150)and aforever. - Inside: two
if <> thenblocks withkey [left arrow v] pressed?andkey [right arrow v] pressed?. - Add two more: if
(x position)is past −215 or 215, put it back withset x to (-215)orset x to (215).
when flag clicked
go to x: (0) y: (-150)
forever
if <key [left arrow v] pressed?> then
change x by (-6)
end
if <key [right arrow v] pressed?> then
change x by (6)
end
if <(x position) < (-215)> then
set x to (-215)
end
if <(x position) > (215)> then
set x to (215)
end
end
How to use this: Click the green flag, click the stage once, then hold ← or → to slide the ship. Try to drive it off the edge.
Basic — the army and the ship 25 min
New project. Pick the Stars backdrop. Then two sprites.
Step 1 — the invader’s costumes
- Paint a small invader. Squares are enough — make it about 30 wide.
- Right-click it and duplicate it four times. Recolour each copy.
- Or choose costumes from the library instead: Crab, Beetle, Ghost, Dragonfly, Bat.
- Check the order: costume 1 is the back row, costume 5 the front.
Step 2 — the two counters
- Make
my rowandmy column, both For this sprite only. - Untick their boxes so they do not cover the army.
Step 3 — the grid
- Build the flag stack with the two loops.
- Build the clone stack: costume, then show.
- Press the flag and count. Five rows of eight, nothing overlapping.
Step 4 — the click test
- Add the click stack.
- Click the four corners. You should hear 1,1 then 1,8 then 5,1 then 5,8.
- Keep it for now. You can delete it later.
Step 5 — the ship
- Add the Rocketship and its flag stack.
- Hold → for five seconds. The ship must stop with its whole body showing.
- Now hold ←.
How to use this: Click the green flag, click the stage once, then hold ← or → to move the ship under the army.
Only one invader appears.
The go to x: () y: () is outside the small loop. Every clone is made in the same spot, piled on top of each other.
I get one long row that runs off the Stage.
set [my column v] to (1) is missing, or it sits outside the big loop. The column must go back to 1 at the start of every row.
Every row has the same costume.
The clone stack says switch costume to (1) instead of switch costume to (my row). Drag the orange variable into the slot.
Every invader I click says row 6.
The variables are “For all sprites”. Delete them and make them again, this time “For this sprite only”.
An extra invader sits at the bottom right.
The original is showing. It needs hide at the top of the flag stack.
Five rows, five looks
- Every row has its own costume.
- All eight invaders in a row match.
- The back row looks the most dangerous — it will be worth the most.
Two edges
- The ship slides with ← and →.
- It stops at both edges.
- Its whole body stays on the Stage.
- It never turns round or flips over.
Teacher note — why −215 and not −240
A sprite’s x is its middle. The ship is about 38 wide, so at x = −240 half of it is off the Stage. Ask pupils to find the number by trying: go too far, then come back five at a time until the whole ship shows.
Your own army
Make a bigger army. Change numbers only — no new blocks.
- Ten columns instead of eight.
- The whole army still fits on the Stage, with room at both sides.
- No two invaders overlap.
- The click test still gives the right row and column.
Teacher reveal — the four numbers that change
The repeat goes to 10, and the gap has to shrink so ten fit. With a gap of 36, column 10 is at 360. Take away 198 and the army runs from −162 to 162.
repeat (10)
go to x: (((my column) * (36)) - (198)) y: ((172) - ((my row) * (32)))
create clone of [myself v]
change [my column v] by (1)
end
A good question for the pupil: why did the 180 have to change? (Because the army must stay in the middle when it gets wider.)
How to use this: Click the green flag and watch ten columns build. Then click the stage once and hold ← or → to move the ship.
Shields
The real game has four green shields above the ship. Each one is a small grid of bricks. Build them with loops, not by hand.
How to use this: Click the green flag and watch four shields build under the army. Click the stage once, then hold ← or → to move the ship.
Teacher notes — three loops deep
The trick is putting the pen back after each row and each shield. After a row of four, step back 48 and down 9. After a whole shield, step right 110 and back up 18.
when flag clicked
hide
go to x: (-183) y: (-90)
repeat (4)
repeat (2)
repeat (4)
create clone of [myself v]
change x by (12)
end
change x by (-48)
change y by (-9)
end
change x by (110)
change y by (18)
end
when I start as a clone
show
Pupils who get lost here should say it aloud: “four shields, each two rows, each four bricks”. The loops are that sentence, outside to inside. In Lesson 2-43 bombs and lasers will chip these away.
Summary 4 min
- A repeat inside a repeat makes a grid: rows of rows.
- A clone is born with a copy of the original’s “For this sprite only” variables.
- So every invader keeps its own
(my row)and(my column). switch costume to (my row)gives each row its own look.- Two comparisons keep the ship on the Stage.
- Nested loop
- A loop inside another loop. The inside one runs in full each time round.
- Grid
- Things laid out in rows and columns.
- For this sprite only
- A variable each sprite — and each clone — keeps for itself.
- Clamp
- Putting a number back inside its limits when it goes past them.
Next lesson: a laser. Hit an invader and it is gone — and the back row is worth the most.