- 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. The variable is for this sprite only.
- A list can hold a level’s design. It can say where the coins go, or 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 make the bug follow the colour? That is what the Line Follower did 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 player to see. 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 (a group of enemies sent one after another): clones, each with its own
next - Lives (how many bugs the castle can take) 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. Each one keeps track of how far it has got.
- Change how fast, how many and how tough the enemies are, just by changing numbers.
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. Put their y values in path y, in order. A bug starts at corner 1. It 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. It is how far along x plus how far along y. On a straight leg one of those is always 0. Vending Machine’s abs is useful here. And lives never goes below 0. That is because bugs already on the path keep arriving after the castle has fallen.
How to use this: Click the green flag. Follow the one bug from the left edge to the castle.
2 · A wave is clones
One hidden Bug sprite makes the whole wave. It sets the health, makes a clone, waits, and does it again. Every clone runs the walk above for itself. This 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. It goes 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. 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. There are no towers yet.
Step 1 — paint the field
- Paint 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. - Hold the mouse over each corner of your road. Read its x and y under the Stage. Type them in, in order, from the start to the castle.
Step 3 — the bug
- Add a bug sprite at size 40. Hide it 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.
- When the flag is clicked, set
livesto 10 andbugs to sendto 8. Thenbroadcast [wave v].
How to use this: Click the green flag. 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 at the same moment.
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 checker 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. Watch four bugs share one next-corner variable.
next on for the others. 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. Ladybugs walk at 120. Send the beetles first.
- They use 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. Each wave waits for the last to finish.
- A
wavecounter. wait until <(bugs alive) = (0)>between waves.- Start with 20 lives. Count how many bugs get through.
How to use this: Click the green flag. 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. A boss is one big, tough enemy. It is bigger, slower and tougher, and worse for the castle.
- Make 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 comes, 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 one 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, it is a clone.
- Boss
- A single, tougher enemy. It usually comes at the end of a wave.
Hand in
Save your field. Next lesson the castle fights back.