- Learnt28 min · corners in lists, and a wave of clones
- Basic24 min · the march
- Challenge 1–327 min · a shared next, two speeds, growing waves
- Extrabonus · a boss
Review — the Scroll World arc 5 min
- Everything in a big world keeps its own place in a variable made for this sprite only.
- A list can hold a level’s design: where the coins go, which level comes next.
- The original sprite hears broadcasts too, so it has to be one of the copies.
Quick-fire
A bug has to walk a winding path to the castle. Could you paint the path and have the bug follow the colour, like the Line Follower in Level 2?
Reveal the answer
You could, but it is fiddly and slow. A path with sharp corners is easier as a list of corners: glide to the next one, then the next. The road is painted for the eye; the bugs read the lists.
Today’s Topic 3 min
- A path as two lists:
path xandpath y - A glide whose seconds are a sum: distance ÷ speed
- A wave: clones, each with its own
next - Lives lost at the castle gate
Learning outcome
By the end of this lesson you will be able to:
- Make a clone walk any path described in two lists.
- Send a wave of clones that each keep track of their own progress.
- Change how fast, how many and how tough the enemies are with numbers alone.
Learnt — the path and the wave 28 min
1 · The path is a list of corners
The road has seven corners. Put their x values in a list called path x and their y values in path y, in order. A bug starts at corner 1 and glides to each next corner until there are none left:
when I start as a clone
go to x: (item (1) of [path x v]) y: (item (1) of [path y v])
show
set [next v] to (2)
repeat until <(next) > (length of [path x v])>
set [leg v] to (([abs v] of ((item (next) of [path x v]) - (x position))) + ([abs v] of ((item (next) of [path y v]) - (y position))))
glide ((leg) / (speed)) secs to x: (item (next) of [path x v]) y: (item (next) of [path y v])
change [next v] by (1)
end
if <(lives) > (0)> then
change [lives v] by (-1)
end
delete this clone
speed in pixels a second.leg is the distance to the next corner: how far along x plus how far along y. On a straight leg one of those is always 0 — Vending Machine’s abs, earning its keep. And lives never goes below 0, because bugs already on the path keep arriving after the castle has fallen.
How to use this: Click the green flag and follow the one bug from the left edge to the castle.
2 · A wave is clones
One Bug sprite, hidden, makes the whole wave. It sets the health, makes a clone, waits, and does it again. Every clone runs the walk above for itself — which only works because next is for this sprite only.
when I receive [wave v]
repeat (bugs to send)
set [health v] to (bug health)
change [bugs alive v] by (1)
create clone of (myself v)
wait (0.8) seconds
end
bugs alive goes up here and down when a bug reaches the gate, so the game can tell when a wave is over.How to use this: Click the green flag and watch six bugs set off one after another.
Basic — the march 24 min
Start a new project. You are building the field and the enemy — no towers yet.
Step 1 — paint the field
- A grass backdrop, a road that turns only at right angles, and a castle at the end.
- Paint the road in one flat colour — Lesson 3-38’s Extra will ask about it.
Step 2 — the corners
- Make lists
path xandpath y. - Hover the mouse over each corner of your road and read its x and y under the Stage. Type them in, in order, start to castle.
Step 3 — the bug
- Add a bug sprite at size 40, hidden when the flag is clicked.
- Give it
next,healthandspeed, for this sprite only. Setspeedto 100. - Build the clone’s walk from Learnt part 1.
Step 4 — the wave
- Make
lives,bugs alive,bugs to sendandbug health, for all sprites. - Build the wave script from Learnt part 2.
- From the flag: set
livesto 10,bugs to sendto 8, andbroadcast [wave v].
How to use this: Click the green flag and count the bugs that reach the castle.
The bugs slide diagonally across the grass.
A corner is wrong, or one list has an item the other does not. Show both lists on the Stage and read them side by side.
All the bugs arrive at once.
The wait is missing from the wave loop, so every clone is made in the same instant.
Some bugs are very fast on one leg and slow on another.
The glide’s seconds are a fixed number instead of distance ÷ speed. Long legs and short legs then take the same time.
An extra bug stands at the start and never moves.
The original sprite is showing. It must hide: only clones walk.
One next for everybody
Make next for all sprites instead, send four bugs, and count the damage.
- A watcher in each clone counts the moments it is not touching the road colour.
- Watch where the bugs go.
- Explain what went wrong, using the word “share”.
How to use this: Click the green flag and watch four bugs sharing one next-corner variable.
next on for the others, and your own bugs keep to the road.Teacher note
Bubble Popper’s lesson in a new costume: when every clone reads and changes one shared number, each one’s progress is everyone’s progress. The grass-counter makes the fault measurable instead of “it looks odd”.
Two kinds of bug
Add beetles that walk at 60 a second beside ladybugs at 120. Send the beetles first.
- The same walk; only
speedis different. - Each bug adds its kind to an
arrivalslist as it reaches the gate. - Read the list afterwards.
How to use this: Click the green flag. Two beetles set off, then two ladybugs. Watch who arrives first.
Teacher note
Dividing the distance by the speed is what makes this work. A class that typed a fixed glide time in the Basic will find their beetles and ladybugs arrive together — a good moment to go back and fix it.
Waves that grow
Send three waves. Wave n has 2 + 2n bugs, and each waits for the last to finish.
- A
wavecounter. wait until <(bugs alive) = (0)>between waves.- Start with 20 lives and count how many get through.
How to use this: Click the green flag and watch three waves, each bigger than the last. The bugs run at double speed here, so all three fit.
Teacher reveal — the wave loop
set [wave v] to (0)
repeat (3)
change [wave v] by (1)
set [bugs to send v] to ((2) + ((2) * (wave)))
broadcast [wave v] and wait
wait until <(bugs alive) = (0)>
end
broadcast [wave v] and wait only waits until every bug has been made. It is bugs alive that says they have all finished.
A boss
After the wave, send one boss: bigger, slower, tougher, and worse for the castle.
- A Boss sprite: the beetle at size 70, speed 70, health 80.
- It walks the same lists.
- Reaching the gate costs three lives, not one.
How to use this: Click the green flag. A wave of five, and then the boss.
Teacher note
Keep the boss’s code: next lesson, when the towers arrive, its 80 health is the first real test of whether a defence works.
Summary 5 min
- A path is two lists of corners; a bug glides from one to the next.
- A leg’s glide time is its length divided by the bug’s speed.
- A wave is one hidden sprite making clones; each keeps its own
next. bugs alivesays when a wave is really over.
- Waypoint
- A corner on the path that an enemy heads for next.
- Wave
- A group of enemies sent one after another.
- Spawn
- Making a new enemy — here, a clone.
- Boss
- A single, tougher enemy, usually at the end of a wave.
Hand in
Save your field. Next lesson the castle fights back.