- 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. One My Block loads them.
(reloading?)is a state. 1 means busy. It lets two scripts agree.- Save a value before you write over it, or the switch loses it.
Quick-fire
Your game is fun for two minutes. Then it is boring. Nothing is broken. What is missing?
Reveal the answer
A reason to keep playing. Something that changes. It could be harder enemies, something to collect, or something to buy. That is 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 can 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 go up as you buy.
- Make an upgrade change how the game really plays.
Learnt — what keeps a game going 28 min
Five kinds of enemy, one random number
You already have two kinds. Five kinds do not need five times the code. One number does 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 enemy is bigger, tougher and worth five times as much. You wrote one line for each.(level) and (worth) must be for this sprite only, just 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 enemies are stopped, say so. Set the count back to 0, 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 has one costume for each button. One My Block puts them in place.
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 made before always did what you clicked. 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 change the game
An upgrade is not a new part of the game. It changes a number the game already uses:
- 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 them from one pick random (1) to (10).
Step 2 — coins
change [coins v] by (worth) where the clone is stopped.
Step 3 — the wave counter
(killed), (wave) and (wave size). Start with a wave size of 5 for testing. Make it bigger when it works.
Step 4 — the four bonus variables
(damage bonus) (0), (ammo bonus) (0), (reload bonus) (1) and (push) (0.9). Set them when the flag is clicked.
Step 5 — the shop
Make a new sprite with the seven costumes and the Item block. Add the clone script from Lesson 7: hover, click, wait for mouse up.
Step 6 — the four things to buy
Add one if for each button, plus Done.
Step 7 — hook them up
Use the four bonus variables in the places listed above. Then play four waves.
Every zombie is worth the same.
(worth) is “for all sprites”. So the last clone to appear wrote over 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 buying.
The shop opens and the zombies keep coming.
That is a choice, not a bug. Do you want the game to pause? Then broadcast something that the zombie maker waits for. Let Done start it again.
One click buys three upgrades.
You are missing wait until <not <mouse down?>>. It is the same bug as the Car Race menu, with the same fix.
Coins go negative.
The “have enough coins” check is missing. Or it checks the wrong cost variable. That is easy to do, because the four names look alike.
Worth going after
- Five levels of enemy come from one random number.
- Health, size and coin value all come from the level.
- You can see which ones are worth more just by looking.
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
This is the last mission from the slides. A shop makes people want to play again.
- Four upgrades: damage, reload speed, max ammo, movement speed.
- Each one costs coins. The price doubles each time you buy it.
- If you do not have enough coins, you cannot buy it.
- Done closes the shop and the next wave begins.
- You can feel each upgrade when you play.
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. You already know everything you need to finish this game well.
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 can say no. Check before you act.
- Doubling the price is what makes the player choose.
- An upgrade changes a number the game already uses. That only works because you gave those numbers names.
- Wave
- A group 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 coins. It makes a player keep going.
- Game design
- Making the player choose between good options.
Three games in
In twelve lessons of Level 2, you have built a whack-a-mole, a car race and a zombie defence. They have clones with their own health, My Blocks, menus and a shop.
Next comes a treasure hunt. A detector tells you how close you are: hot, warm or cold.
Hand in
Share your finished game. Send the link to your teacher. Well done.