- Learnt28 min · enemy levels, coins, waves, the shop
- Basic24 min · close the loop
- Challenge 1–327 min · levels, waves, upgrades
- Extrabonus · make it yours
Review — where we got to 5 min
- A weapon is a row of numbers, loaded by one My Block.
(reloading?)is a state — 1 for busy — and two scripts agree because of it.- Save a value before you overwrite it, or the switch loses it.
Quick-fire
Your game is fun for two minutes and then boring. Nothing is broken. What is missing?
Reveal the answer
A reason to keep playing. Something that changes: harder enemies, something to collect, something to buy. That is the whole of today.
Today’s Topic 3 min
- Five kinds of enemy from one random number
- Coins, and what an enemy is worth
- Waves
- A shop, and a button that is allowed to say no
Learning outcome
By the end of this lesson you will be able to:
- Make one random number decide several things at once.
- Build a shop where prices rise as you buy.
- Make an upgrade change how the game actually plays.
Learnt — the loop that keeps a game going 28 min
Five kinds of enemy, one random number
You already have two kinds. Five is not five times the code — it is one number doing three jobs:
when I start as a clone
set [level v] to (pick random (1) to (5))
set [hp v] to ((level) * (3))
set [worth v] to ((level) * (8))
set size to ((45) + ((level) * (6))) %
show
(level). A level-5 walker is bigger, tougher and worth five times as much, and you wrote one line for each.(level) and (worth) must be for this sprite only, exactly like (hp).
if <(hp) < (1)> then
change [coins v] by (worth)
change [killed v] by (1)
change [score v] by (1)
delete this clone
end
Waves
A wave is just a count. When enough have fallen, say so, reset the count, and let the player go shopping.
when flag clicked
set [wave v] to (1)
set [killed v] to (0)
forever
wait until <not <(killed) < (wave size)>>
set [killed v] to (0)
change [wave v] by (1)
say [WAVE 2] for (1) seconds
broadcast [Store v]
end
The shop
You have built this before. It is the Car Race menu again: one sprite, one costume per button, one My Block placing them.
when I receive [Store v]
hide
Item (0) (0) [Box] (100) :: custom
Item (0) (118) [Upgrades] (80) :: custom
Item (0) (58) [Damage] (62) :: custom
Item (0) (12) [Reload Speed] (62) :: custom
Item (0) (-34) [Max Ammo] (62) :: custom
Item (0) (-80) [Speed] (62) :: custom
Item (0) (-128) [Done] (62) :: custom
A button that can say no
Here is the new part. Every menu you have made so far always did what it was clicked for. This one checks first:
if <(costume [name v]) = [Damage]> then
if <not <(coins) < (cost - Damage)>> then
change [coins v] by ((0) - (cost - Damage))
change [damage bonus v] by (1)
set [cost - Damage v] to ((cost - Damage) * (2))
end
end
Upgrades that reach back into the game
An upgrade is not a new feature. It changes a number the game has already been reading all along:
- Damage → the zombie takes
(damage) + (damage bonus)off its health. - Speed →
(push), the number your movement loop has used since Lesson 10. - Max Ammo → the reload fills to
(max ammo) + (ammo bonus). - Reload Speed → the reload waits
(reload speed) * (reload bonus).
Basic — close the loop 24 min
Step 1 — enemy levels
(level) and (worth), both for this sprite only, set from one pick random (1) to (10).
Step 2 — coins
change [coins v] by (worth) where the clone dies.
Step 3 — the wave counter
(killed), (wave) and (wave size). Start with a wave size of 5 for testing, and raise it when it works.
Step 4 — the four bonus variables
(damage bonus) (0), (ammo bonus) (0), (reload bonus) (1) and (push) (0.9). Set them at the flag.
Step 5 — the shop
New sprite, the seven costumes, the Item block, and the clone script from Lesson 7 — hover, click, wait for mouse up.
Step 6 — the four purchases
One if per button, plus Done.
Step 7 — hook them up
Use the four bonus variables where the lesson lists them above. Then play four waves.
Every zombie is worth the same.
(worth) is “for all sprites”, so the last clone to spawn overwrote it for everybody. Make it for this sprite only.
I can buy the same upgrade for ever.
The price is not doubling. That line goes inside the same if as the purchase.
The shop opens and the zombies keep coming.
That is a choice, not a bug — but if you want it to pause, broadcast something the zombie spawner waits on, and let Done release it.
One click buys three upgrades.
You are missing wait until <not <mouse down?>>. The same bug as the Car Race menu, and the same fix.
Coins go negative.
The affordability check is missing, or it is checking the wrong cost variable — easy to do when four of them have such similar names.
Worth going after
- Five levels of enemy from one random number.
- Health, size and coin value all come from the level.
- You can tell a valuable one by looking at it.
Waves
- A set number of kills ends the wave.
- The wave number goes up and the game says so.
- The count starts again.
- Something about the next wave is harder.
Teacher note
The easiest “harder” is fewer seconds between spawns. One line, and it changes the whole feel. Ask what else could get harder, and whether making the enemies tougher is more or less fun than making them more frequent — there is no right answer, which is the point.
The shop
The deck’s last mission, and the thing that turns a game into a game you replay.
- Four upgrades: damage, reload speed, max ammo, movement speed.
- Each costs coins, and each doubles in price when bought.
- What you cannot afford, you cannot buy.
- Done closes the shop and the next wave begins.
- Every upgrade makes a difference you can feel.
Teacher reveal — why prices double
Ask what happens if the price stays at 50. Somebody will work it out: buy damage twenty times and nothing can survive a single shot. The game solves itself.
Doubling means the fifth upgrade costs sixteen times the first, so the player has to choose. Making the player choose is most of what game design is, and this is the cheapest possible example of it.
Make it yours
This is the last lesson of Level 2. Everything you need to finish this game properly, you already know.
Summary 5 min
- One random number can decide several things at once.
- A wave is a count and a message. That is all.
- A button is allowed to refuse. Check before you act.
- Doubling the price is what makes the player choose.
- An upgrade changes a number the game already reads — which is only possible because you gave those numbers names.
- Wave
- A batch of enemies. Survive it and the next one is harder.
- Upgrade
- Something you buy that changes a number in the game.
- Economy
- Earning and spending. It is what makes a player keep going.
- Game design
- Making the player choose between good options.
Three games in
Twelve lessons into Level 2 you have built a whack-a-mole, a car race and a zombie defence — with clones that remember their own health, custom blocks, menus and a shop.
Next comes a treasure hunt, where a detector has to decide how close you are: hot, warm or cold.
Hand in
Share your finished game and send the link to your teacher. Well done.