- Learnt28 min · levels, prices and reach from lists
- Basic24 min · the defence
- Challenge 1–327 min · balance, win and lose, a best
- Extrabonus · ship it
Review — money 5 min
- Check the money before building. Kills pay money in the script that counts them.
- Pads are clones that know their
my spotand remember they areused. - A wave is a group of bugs sent together. A bonus between waves gives the player time to plan.
Quick-fire
A level 2 tower costs 60 to reach. A level 3 costs 90. Where would you keep those numbers? A teacher should be able to change them without reading your scripts.
Reveal the answer
In a list. upgrade cost holds 60, then 90. A tower at level 1 pays item 1. A tower at level 2 pays item 2. Change the list and the game changes. The level order in Scroll World worked the same way.
Today’s Topic 3 min
- A tower’s own
level, for this sprite only. upgrade costandupgrade range: the price and the reach at each level.- A top level, worked out from the length of a list.
- Winning and losing, with Storm Flight’s state.
Learning outcome
By the end of this lesson you will be able to:
- Upgrade a clone. Its own level picks its price and reach from lists.
- Make a game fairer by changing data, not code.
- End a game in a won or a lost state.
Learnt — upgrades 28 min
1 · An upgrade is two list items
Every tower clone keeps its own level, starting at 1. Two lists hold the upgrades. upgrade cost is 60, 90. upgrade range is 184, 240, 300. These are the ring’s sizes at levels 1, 2 and 3.
define upgrade me
if <(money) < (item (level) of [upgrade cost v])> then
set [last upgrade v] to [not enough money]
else
change [money v] by ((0) - (item (level) of [upgrade cost v]))
change [level v] by (1)
switch costume to (join [tower ] (level))
set [range size v] to (item (level) of [upgrade range v])
set [build spot v] to (my spot)
set [last upgrade v] to (join [now level ] (level))
broadcast [upgrade v] and wait
end
when this sprite clicked
upgrade me :: custom
upgrade and changes its size.How to use this: Click the green flag. A tower is bought on pad 2, then upgraded twice.
2 · The top
Two prices in the list means three levels. When a tower’s level is bigger than the length of the list, it is at the top:
if <(level) > (length of [upgrade cost v])> then
set [last upgrade v] to [already at the top]
else
upgrade me :: custom
end
How to use this: Click the green flag. A tower on pad 3 is upgraded three times, with plenty of money.
Basic — the defence 24 min
Open your shop from last lesson and make the towers upgradable.
Step 1 — three looks
- Give the Tower two more costumes,
tower 2andtower 3. Draw them in the same place so nothing moves. - Give it
level, for this sprite only. A new tower starts at 1.
Step 2 — the lists
upgrade cost: 60, 90.upgrade range: 184, 240, 300.
Step 3 — upgrade me
- Build the My Block from Learnt part 1 on the Tower. Put part 2’s top check around it.
- Range:
when I receive [upgrade v]→ ifmy spotisbuild spot, set size torange size.
Step 4 — win or lose
- Repeat waves until the third is over or lives reach 0.
- Then set
statetowonorover, and say which.
How to use this: Click the green flag. Click pads to build, click towers to upgrade. Survive three waves.
An upgrade costs double.
The original Tower is answering too. Put the is clone check on every broadcast that is meant for one tower.
The tower changes costume but the ring stays small.
The Range never heard which pad to resize. Or range size was set after the broadcast. Set it first, then broadcast and wait.
A level 3 tower upgrades to “tower 4” and turns invisible.
The top check is missing. That is Learnt part 2.
The game keeps sending waves after the castle falls.
The wave loop only counts waves. It must also stop when lives reaches 0.
The list is the balance
Run the same wave against a level 2 tower twice. Change only one item of upgrade range between the runs.
- First with 240 (reach 120), then with 300 (reach 150).
- Use
replace item (2) of [upgrade range v] with (300). Nothing else changes. - Record the kills each time.
How to use this: Click the green flag. The same wave runs twice. Between the runs, one number in a list changes.
Teacher note
Game designers call this tuning, and it is done in exactly this way — in tables, not code. A tuning pass where each pupil changes one list item and a partner plays it is a very good use of ten minutes.
Winning and losing
The game must end one way or the other, and stop sending waves when it does.
- Repeat waves until
waveis 3 orlivesis below 1. - Then
stateiswonif there are lives left, andoverif not. - Test the losing ending on purpose, with no towers.
How to use this: Click the green flag. There are no towers, six lives and four bugs in each wave. Watch where it stops.
Teacher reveal — the loop
repeat until <<(wave) = (3)> or <(lives) < (1)>>
change [wave v] by (1)
set [bugs to send v] to (4)
broadcast [wave v] and wait
wait until <(bugs alive) = (0)>
end
if <(lives) > (0)> then
set [state v] to [won]
else
set [state v] to [over]
end
Storm Flight’s state again, used for its oldest job: telling every script that the game has finished, and how.
The furthest wave
Keep a best wave. A worse game must not lower it.
- Set it to 0 only when the project is opened.
- At the end of every game, raise it if this game went further.
How to use this: Click the green flag. Two games are played. The second goes worse than the first.
best wave never goes down between games.Teacher note
The fourth “best” in this level — high score, best time, best level, best wave — and by now nobody should need the pattern shown. If a pupil does, point them at their own Cheese Maze.
Ship it
Put the four lessons together into one tower defence game. Make it good enough to give to someone else.
- A title that explains clicking pads and towers.
- Four waves that grow, a bonus between them, and a boss (one big, strong bug) at the end.
- Buying, selling and upgrading, with prices from lists.
- Won and over endings, and a best wave.
How to use this: Click the green flag and read the title. Click pads to build and towers to upgrade. Four waves come, then the boss.
Teacher note
Every tool in Level 3 is in this one project: clones (the bugs, the towers, the pads), lists (the path, the pads, the prices), My Blocks (buy, upgrade), sprite-only variables (health, level, my spot) and game state (title, play, won, over). It is worth saying so out loud when they finish.
Summary 5 min
- A tower’s own
levelpicks its price and reach from two lists. - The top level is the length of the price list plus one.
- Edit the lists to make the game fairer. The scripts stay the same.
- The original sprite must ignore a broadcast meant for one clone. Check
is clone. - Loop waves until the game is won or lost, then say which.
- Upgrade
- Paying to make something you already own better.
- Tuning
- Changing numbers to make a game fairer or harder, without changing its code.
- Lookup table
- A list you read by position: level 2’s price is item 2.
- Synthesis
- Putting separate ideas together into one working thing.
Hand in
Save your game. You have finished the four Tower Defence lessons. You used every tool from Level 3 in one project.