- Learnt28 min · friction as a setting, health per clone, hearts
- Basic24 min · build the real game
- Challenge 1–327 min · tune it, toughen it, lose it
- Extrabonus · design four weapons
Review — the draft 5 min
- The crosshair follows the mouse; the player points at it.
point towards [mouse-pointer v]runs once, when the bullet is born.- The player makes the bullet clone, so bullets do not clone each other.
Quick-fire
Two zombie clones are on screen. You set a variable called hp to 6. What happened to the other clone’s hp?
Reveal the answer
It depends. If hp is “for all sprites”, they share one number and you just changed both. If it is “for this sprite only”, each clone has its own. Today you find out why that matters.
Today’s Topic 3 min
- Friction as a setting you can tune
- Splitting setup from control
- A variable that belongs to one clone
- Tough enemies
- Lives, hearts, and losing
Learning outcome
By the end of this lesson you will be able to:
- Change how a game feels by changing one named number.
- Give every clone its own health.
- Show lives on screen and end the game when they run out.
Learnt — a game you can lose 28 min
Friction with a name
Your car had set [speed v] to ((speed) * (0.9)). That 0.9 is hiding a good idea. Give it a name:
set [friction v] to (0.1)
set [push v] to (0.9)
set [vx v] to ((vx) * ((1) - (friction)))
set [vy v] to ((vy) * ((1) - (friction)))
Now try 0.02 and then 0.4. One is ice; the other is mud. You did not touch the movement code once.
A variable that belongs to one clone
When you make a variable, Scratch asks you a question you have always ignored: for all sprites or for this sprite only?
- For all sprites — one number, shared by everything. Your
(score)should be this. - For this sprite only — every clone gets its own copy. Your
(hp)must be this.
Make (hp) the second kind, and one script can run twenty zombies each with their own health.
Two kinds of zombie
when I start as a clone
if <(pick random (1) to (3)) = (1)> then
set [hp v] to (6)
set size to (75) %
else
set [hp v] to (3)
set size to (55) %
end
show
if <touching [Bullet v]?> then
change [hp v] by (-1)
switch costume to [skeleton-b v]
wait (0.12) seconds
switch costume to [skeleton-a v]
if <(hp) < (1)> then
change [score v] by (1)
delete this clone
end
end
They come for you
Last lesson the zombies walked straight across. Now they aim at you, every step:
point towards [Human v]
move (1.1) steps
Three lives
A (lives) variable, and hearts drawn the way you drew digits in Lesson 4:
when flag clicked
hide
set [lives v] to (3)
forever
if <(lives) > (0)> then
go to x: (-205) y: (155)
create clone of [myself v]
end
if <(lives) > (1)> then
go to x: (-172) y: (155)
create clone of [myself v]
end
if <(lives) > (2)> then
go to x: (-139) y: (155)
create clone of [myself v]
end
end
And a zombie that reaches you costs one:
if <touching [Human v]?> then
if <(lives) > (0)> then
change [lives v] by (-1)
end
delete this clone
end
Basic — build the real game 24 min
Open last lesson’s draft. Six sprites when you are done: Human, Aim, Bullet, Zombie, Heart, Referee.
Step 1 — split the human
Move the position, size and rotation style into a setup stack that ends with broadcast [Control v]. Put the forever loop on when I receive [Control v].
Step 2 — the two settings
(friction) and (push), set in the setup and used in the loop.
Step 3 — hp, for this sprite only
Make it, and check the box. Then the two-kinds if / else in when I start as a clone.
Step 4 — they aim at you
point towards [Human v] at the top of the walking loop, and set rotation style [left-right v] so they stay the right way up.
Step 5 — hearts
The heart sprite and its clone script.
Step 6 — losing
The referee, the Over broadcast, and YOU LOSE.
Step 7 — play three games
If you never lose, the zombies are too slow. If you always lose, they are too fast.
All the zombies die together.
(hp) is “for all sprites” — they are sharing one number. Make a new variable with “for this sprite only” ticked.
One bullet takes off six lives at once.
The touching check runs every frame while they overlap. The wait (0.12) seconds is what stops it — and the bullet should delete itself on contact too.
Lives go to −2.
Several zombies reached you in the same instant. Wrap the subtraction in if <(lives) > (0)> then.
YOU LOSE appears but the zombies keep walking.
Broadcast Over before you stop anything, and give the zombie a when I receive [Over v] → delete this clone.
Tune the feel
(friction)and(push)are named settings, not numbers buried in blocks.- Setup and control are separate stacks.
- You have tried at least three different friction values and chosen one.
Tougher enemies
(hp)is for this sprite only.- Two kinds: a normal one and a big one that takes twice the shooting.
- You can see when a hit lands.
- They walk towards you, not past you.
Teacher note
Have them build it with hp “for all sprites” first and watch every zombie on screen die from one bullet. Ten seconds of that explains the checkbox better than any description, and it is the first time in the course that the choice has ever mattered.
A game you can lose
The deck’s mission — the first version that is really a game.
- Three lives, shown as hearts.
- A zombie that reaches you costs one.
- At zero, everything stops and the game says so.
- Your score is still on screen at the end.
Teacher reveal — is it fun?
This is the first lesson where the answer might be no, and that is worth saying out loud. A game that is too easy is boring; too hard and nobody plays twice. The numbers to turn are the spawn wait, the zombie speed and the number of lives.
Ask each pupil to hand their game to the person next to them and watch without speaking. Where the other person struggles is the answer.
Design four weapons
Next lesson your player gets weapons. A weapon is not a picture — it is a set of numbers.
- Damage — how much health it takes off
- Fire rate — how long between shots
- Ammo — how many before reloading
- Reload — how long that takes
Summary 5 min
- Give your numbers names. A setting you can find is a setting you will tune.
- For this sprite only gives every clone its own copy of a variable. That is how one script runs twenty enemies with different health.
- Show the player when a hit lands, or they will think it did not.
point towards [Human v]turns a walker into a hunter.- A game becomes a game when you can lose it.
- Friction
- How fast speed leaks away. Higher means it stops sooner.
- hp
- Health points — how many hits something takes.
- For this sprite only
- A variable each clone owns separately.
- Game over
- Everything stops, and the player is told why.
Hand in
Share your game and send the link to your teacher, with your table of four weapons. Next lesson you build them.