- Learnt28 min · a tower is a ring; building from a list
- Basic24 min · defend
- Challenge 1–327 min · shared health, reach, spreading out
- Extrabonus · not on the road
Review — the path and the waves 5 min
- A path is two lists of corners; a bug glides corner to corner.
- A wave is one hidden sprite making clones, each with its own
next. bugs alivetells the game when a wave is over.
Quick-fire
A tower should shoot the nearest bug. Why can’t the tower just use point towards (Bug v)?
Reveal the answer
Because the bugs are clones. point towards and distance to can only name a sprite, and they always mean the original — the hidden one that never moves. No block names one particular clone. So today the question is turned round: the bug asks whether it is near a tower.
Today’s Topic 3 min
- A tower’s reach as a ring:
<touching (Range v)?> - A bug’s own
health, and deleting itself at 0 - Building towers on pads read from two lists
- Why only the original sprite may build
Learning outcome
By the end of this lesson you will be able to:
- Make clones take damage from something they are touching.
- Place towers from a list of positions without the old ones moving.
- Judge where a tower does the most good, and prove it with a count.
Learnt — towers 28 min
1 · The bug asks
A tower is two sprites: the tower you see, and a Range — a faint circle around it showing how far it reaches. Every bug runs a second script, alongside its walk:
when I start as a clone
forever
if <touching (Range v)?> then
change [health v] by (-1)
end
if <(health) < (1)> then
change [kills v] by (1)
change [bugs alive v] by (-1)
delete this clone
end
end
How to use this: Click the green flag. One tower, one bug — watch the bug flash as it passes through the ring.
2 · Towers from a list, built by the original
The pads are two more lists, spot x and spot y. To build on pad n, set build x and build y from the lists and broadcast build tower. Tower and Range both answer, each leaving a clone there.
Here is the trap, and this lesson’s demos fell into it first. Clones hear broadcasts too. Every tower already built heard build tower, moved to the new pad and cloned itself — so building on pads 3 and 4 put every ring on pad 4. Only the original may build:
when I receive [build tower v]
if <(is clone) = (0)> then
go to x: (build x) y: (build y)
create clone of (myself v)
end
when I start as a clone
set [is clone v] to (1)
show
is clone at 0; every clone sets its own to 1 the moment it starts, and ignores build tower from then on.How to use this: Click the green flag. Two towers go up on pads 2 and 3, then a wave of six comes.
Basic — defend 24 min
Open your field from last lesson and give the castle two towers.
Step 1 — draw a tower and a ring
- A Tower sprite: a small stone tower, about 44 wide.
- A Range sprite: a circle of radius 50, filled very faintly, with a dashed edge. Name it
Range. - Mark five pads on your field and list their x and y in
spot xandspot y.
Step 2 — build
- Give Tower and Range an
is clonevariable, for this sprite only. - Build the two scripts from Learnt part 2 in both sprites. Range also sets its size to 184.
- From the flag, build on two pads before the wave starts.
Step 3 — the bug fights back… or not
- Add the hurt script from Learnt part 1 to the Bug.
- Set
bug healthto 30 andkillsto 0 at the start. - Send a wave of ten.
How to use this: Click the green flag. Two towers go up, then ten bugs come down the road.
All my towers end up on the last pad.
The build script is missing its is clone check — see Learnt part 2.
The bugs walk straight through the rings.
The sprite is not called exactly Range, or the touching block names a different sprite. Check the dropdown.
A dead bug still reaches the castle.
The bug hides instead of deleting itself, so its walk carries on. It must delete this clone.
The rings hide the bugs.
Send the Range clones to the back layer.
One health for everybody
Make health for all sprites, and count the bugs that die outside the ring.
- One tower on pad 2, a wave of eight.
- When a bug dies, if it is not touching a Range, add one to
died out of reach. - Explain what the tower is really doing to the other bugs.
How to use this: Click the green flag and watch where the bugs are when they vanish.
Teacher note
Most pupils predict the opposite — that nobody dies, because each new bug resets the health to full. Both happen: the number bounces up and down, and the moment it touches 0, every bug reading it deletes itself. It is the shared-variable bug from Lesson 3-18 with a very visible result.
How far should a tower reach?
One tower on pad 2. Run the same wave with a small ring, then with a big one.
- Reach 55 (size 110), then reach 120 (size 240).
- Record the kills for each.
- Decide what a bigger ring should cost.
How to use this: Click the green flag. The same wave twice: small ring, then big ring.
Teacher note
A ring twice as wide covers far more than twice as much road, because the road bends round the pad — the big ring touches three legs. Keep this for Lesson 3-40, where reach is what an upgrade buys.
Spread them out
Two towers. Put both on pad 3, then one on pad 3 and one on pad 4. Tough bugs, health 115.
- Count the kills each way.
- Explain the result using
<touching (Range v)?>.
How to use this: Click the green flag. The same six tough bugs, against stacked towers and then spread ones.
Teacher note
touching answers yes or no, so a bug inside two rings on the same spot loses one point a tick, not two. Spreading the towers adds a second stretch of road where bugs are hurt. It is a limit of this design that a real game would fix — and a pupil who notices it has understood exactly how the code works.
Not on the road
Let the player build anywhere — but a tower must refuse to stand on the road. Cheese Maze’s colour question, in a new job.
- The original Tower goes to the chosen spot first.
- If
<touching color [#C9A26B]?>, it refuses; otherwise it clones. - Count what is built and what is refused.
How to use this: Click the green flag. Three places are tried; watch which get a tower.
Teacher note
A sprite that is hidden is never “touching” another sprite, but it can still be asked about colours on the Stage. If a class finds the colour test never fires, check the road is really one flat colour.
Summary 5 min
- No block can aim at one clone, so the bug asks whether it is in a tower’s ring.
- Each bug has its own
health, and deletes itself at 0. - Clones hear broadcasts too: only the original builds.
- Reach matters more than numbers; two rings on one spot are no better than one.
- Range
- How far a tower reaches, drawn as a ring.
- Health
- How much damage a bug can take before it is gone.
- Original
- The sprite itself, as opposed to one of its clones.
- Coverage
- How much of the road is inside a ring.
Hand in
Save your game. Next lesson, towers cost money — and zapping bugs earns it.