- Learnt28 min · a pattern list, moves as spots, a fair gap
- Basic25 min · the dragon with a pattern
- Challenge 1–327 min · a new order, a slam, a fair shuffle
- Extrabonus · a ring of fire
Review — Boss Tower I 5 min
- One
phasevariable, four values: idle, wind-up, attack, recover. - The wind-up is the tell. The recover is the window.
- Each phase ends by naming the next one.
Quick-fire
The dragon’s attack is always one fireball, at the knight. After three fights, what does a player stop doing?
Reveal the answer
Paying attention. One attack is learnt in a minute. Today the dragon gets three, in an order it reads from a list.
Today’s Topic 3 min
- A
patternlist the boss steps through - A move as a list of spots, shared by the warning and the fire
- Many fireballs at once, as clones
- A fair pattern: there is always a gap
Learning outcome
By the end of this lesson you will be able to:
- Make a sprite step through a list, and start again at the end.
- Turn one list into a row of clones, each in its own place.
- Check an attack can always be dodged.
Learnt — moves from lists 28 min
1 · The pattern is a list
The dragon now knows three moves: fireball, rain and sweep. A list called pattern holds them in order. A variable called step says which one is next.
- The wind-up reads
(item (step) of [pattern v]). - The attack adds 1 to
step. - When
stepruns past the end of the list, it goes back to 1.
when flag clicked
go to x: (0) y: (70)
set [step v] to (1)
set [phase v] to [idle]
forever
if <(phase) = [idle]> then
switch costume to [dragon-a v]
glide (1.2) secs to x: (pick random (-150) to (150)) y: (70)
set [phase v] to [wind-up]
end
if <(phase) = [wind-up]> then
switch costume to [dragon-b v]
plan (item (step) of [pattern v]) :: custom
broadcast [warn v]
wait (1) seconds
set [phase v] to [attack]
end
if <(phase) = [attack]> then
switch costume to [dragon-c v]
broadcast [fire v]
change [step v] by (1)
if <(step) > (length of [pattern v])> then
set [step v] to (1)
end
wait (1) seconds
set [phase v] to [recover]
end
if <(phase) = [recover]> then
switch costume to [dragon-a v]
glide (0.4) secs to x: (x position) y: (0)
wait (1.2) seconds
glide (0.4) secs to x: (x position) y: (70)
set [phase v] to [idle]
end
end
How to use this: Click the green flag to start it. Nothing else to press — watch step count up and the move change.
2 · A move is a list of spots
Every move is just “fire falls at these x positions”. So a My Block called plan turns the move’s name into a second list, spots.
define plan (name)
set [move v] to (name)
delete all of [spots v]
if <(name) = [fireball]> then
add (knight x) to [spots v]
end
if <(name) = [rain]> then
set [gap v] to (pick random (1) to (5))
set [lane v] to (1)
repeat (5)
if <not <(lane) = (gap)>> then
add ((-270) + ((lane) * (90))) to [spots v]
end
change [lane v] by (1)
end
end
if <(name) = [sweep]> then
set [lane v] to (200)
repeat (8)
add (lane) to [spots v]
change [lane v] by (-45)
end
end
Now the Marker and the Fireball both read spots. One list, two readers — so the warning and the fire can never disagree.
when I receive [fire v]
set [i v] to (1)
repeat (length of [spots v])
set [my x v] to (item (i) of [spots v])
create clone of [myself v]
change [i v] by (1)
wait (0.08) seconds
end
when I start as a clone
go to x: (my x) y: (40)
show
repeat until <(y position) < (-150)>
change y by (-8)
if <touching [Knight v]?> then
change [burns v] by (1)
delete this clone
end
end
delete this clone
when I receive [warn v]
set [i v] to (1)
repeat (length of [spots v])
set [my x v] to (item (i) of [spots v])
create clone of [myself v]
change [i v] by (1)
end
when I start as a clone
go to x: (my x) y: (-150)
repeat (5)
show
wait (0.1) seconds
hide
wait (0.1) seconds
end
delete this clone
How to use this: Click the green flag to start it. Nothing else to press — the dragon calls out the empty lane each time.
3 · Fair means a gap
A pattern is fair when a player who reads the warning can always get out. Rain with all five lanes burning is not hard. It is impossible.
How to use this: Click the green flag to start it. Nothing else to press — the knight reads each warning and runs to the gap.
How to use this: Click the green flag to start it. Nothing else to press — the same knight, the same rain, with a gap this time.
Basic — the dragon with a pattern 25 min
Open your boss fight from last lesson.
Step 1 — the lists and variables
- Make two lists for all sprites:
patternandspots. - Type
fireball,rainandsweepintopattern, one per line. - Variables for all sprites:
step,moveandgap. On the Dragon only:lane. - On the Fireball and on the Marker, for that sprite only:
my xandi.
Step 2 — the plan
- On the Dragon, make a block called
planwith one input,name. Tick Run without screen refresh. - Build the plan from Learnt section 2.
Step 3 — the brain
- Add
set [step v] to (1)under the green flag. - Rebuild the wind-up and the attack as in Learnt section 1.
Step 4 — fire and markers
- Replace the Fireball’s clone script with the two from Learnt section 2. Keep
hideon its green flag. - Do the same for the Marker.
- Play. Watch the floor, and stand where it does not blink.
How to use this: Click the green flag, then click the stage once and hold ← or → to move the Knight. Press the space bar to throw a bolt.
The rain fills all five lanes.
The if <not <(lane) = (gap)>> then is missing, or it is outside the repeat.
All the fireballs fall in one place.
my x is for all sprites. Delete it and make it again, for this sprite only.
The dragon does the first move, then nothing.
step went past the end of the list, so the item is empty. Check the if <(step) > (length of [pattern v])> then.
A new order
Change how the dragon fights without changing a single script.
- The dragon does: fireball, fireball, rain, sweep — then starts again.
- No script is touched. Only the list.
How to use this: Click the green flag, then click the stage once and hold ← or → to move the Knight. Press the space bar to throw a bolt.
Teacher note
Type a second fireball into the list watcher, above rain. The wrap-around uses (length of [pattern v]), so it follows the list without being told. That is the point of the lesson: the pattern is data.
The slam
Teach the dragon a fourth move.
slam: the dragon dives to the floor where the knight stood at the wind-up.- If it lands on the knight, that is a burn.
- The floor blinks there first, like every other move.
- No fireballs fall during a slam.
How to use this: Click the green flag to start it. Nothing else to press — the knight stands still for the first slam and moves away from the second.
slam in it dives at you, and moving away during the blink always saves you.Teacher reveal
In the plan:
if <(name) = [slam]> then
add (knight x) to [spots v]
end
In the attack, after the broadcast:
if <(move) = [slam]> then
glide (0.25) secs to x: (item (1) of [spots v]) y: (-95)
if <touching [Knight v]?> then
change [burns v] by (1)
end
wait (0.3) seconds
glide (0.4) secs to x: (x position) y: (70)
end
And the Fireball’s receiver is wrapped in if <not <(move) = [slam]>> then. The Marker needs nothing: it already blinks at every spot.
Random, but fair
A fixed order can be learnt by heart. Shuffle it — carefully.
- Each wind-up picks a random move from the pattern list.
- The same move never comes twice in a row.
- A
historylist on the Stage shows every move so far.
How to use this: Click the green flag to start it. Nothing else to press — compare the two lists: plain random on the left, the rule on the right.
Teacher reveal
define pick next move
repeat until <not <(next) = (last)>>
set [next v] to (item (pick random (1) to (length of [pattern v])) of [pattern v])
end
set [last v] to (next)
The wind-up calls it, adds next to history, then plan (next) :: custom. Ask what happens with only one move in the list: the loop never ends. Fairness rules can trap the boss too.
A ring of fire
Not every move falls straight down.
- A
ringmove: fireballs fly out from the dragon in every direction. - One every 30 degrees — but two neighbours are missing, so there is a way through.
- The missing pair is different each time.
How to use this: Click the green flag to start it. Nothing else to press — watch each ring and find its gap.
Teacher reveal
when I receive [ring v]
set [my dir v] to (0)
repeat (12)
if <not <<(my dir) = (gap dir)> or <(my dir) = (((gap dir) + (30)) mod (360))>>> then
create clone of [myself v]
end
change [my dir v] by (30)
end
when I start as a clone
go to x: (0) y: (40)
point in direction (my dir)
show
repeat (45)
move (6) steps
end
delete this clone
The dragon’s wind-up sets set [gap dir v] to ((pick random (0) to (11)) * (30)).
Summary 5 min
- A
patternlist and astepvariable make a boss that follows a routine. - A new order, or a new move in the list, needs no new script.
- A move is a list of spots. The warning and the fire both read it, so they always agree.
- A fair attack always leaves a gap a reading player can reach.
- Pattern
- The order a boss does its moves in.
- Step
- Which item of a list comes next.
- Fair
- Always beatable by a player who reads the warning.
- Gap
- The safe place an attack leaves on purpose.
Hand in
Save your boss fight. Next lesson the dragon gets a health bar drawn with the Pen — and at half health, it gets angry.