- 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 made.- The player makes the bullet clone. So bullets do not clone each other.
Quick-fire
Two zombie clones are on screen. One of them sets a variable called hp to 6. hp means health points. What happened to the other clone’s hp?
Reveal the answer
It depends. If hp is “for all sprites”, they share one number. 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 number with a name.
- Give every clone its own health.
- Show lives on screen, and end the game when they run out. Lives are how many times you can be hit before you lose.
Learnt — a game you can lose 28 min
Friction with a name
Your car had set [speed v] to ((speed) * (0.9)). Let’s give that number 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 like ice. The other is like mud. You did not change the movement code at all.
A variable that belongs to one clone
When you make a variable, Scratch asks you a question. You have always skipped it: 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. Then one script can run twenty zombies, each with its 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 on every step:
point towards [Human v]
move (1.1) steps
Three lives
Make a (lives) variable. Draw hearts 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. When you are done, you will have six sprites: Human, Aim, Bullet, Zombie, Heart, Referee.
Step 1 — split the human
Move the position, size and rotation style into a setup stack. End it with broadcast [Control v]. Put the forever loop under when I receive [Control v].
Step 2 — the two settings
Set (friction) and (push) in the setup. Use them in the loop.
Step 3 — hp, for this sprite only
Make it, and tick the box. Then add the two-kinds if / else to when I start as a clone.
Step 4 — they aim at you
point towards [Human v] at the top of the walking loop. Add set rotation style [left-right v] so they stay the right way up.
Step 5 — hearts
Build the heart sprite and its clone script.
Step 6 — losing
Build 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”, so they share one number. Make a new variable with “for this sprite only” ticked.
One bullet takes off six lives at once.
The touching check runs again and again while they touch. The wait (0.12) seconds stops it. The bullet should also delete itself when it hits.
Lives go to −2.
Several zombies reached you at the same moment. Put the minus block inside if <(lives) > (0)> then.
YOU LOSE appears but the zombies keep walking.
Broadcast Over before you stop anything. Give the zombie a when I receive [Over v] → delete this clone.
Tune the feel
(friction)and(push)are named settings, not numbers hidden in blocks.- Setup and control are two different stacks.
- You have tried at least three friction numbers and chosen one.
Tougher enemies
(hp)is for this sprite only.- Two kinds: a normal one, and a big one that takes twice as many shots.
- 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
This is the mission from the slides. It is 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 just a picture. It is a set of numbers.
- Damage — how much health it takes off
- Fire rate — how long between shots
- Ammo — how many shots before you reload
- Reload — how long that takes
Summary 5 min
- Give your numbers names. Then they are easy to find and change.
- For this sprite only gives every clone its own copy of a variable. So one script can run twenty enemies, each with its own health.
- Show the player when a hit lands. If you do not, they will think it missed.
point towards [Human v]makes an enemy chase you.- A game becomes a game when you can lose it.
- Friction
- How fast speed drains away. Higher means it stops sooner.
- hp
- Health points — how many hits something takes.
- For this sprite only
- Each clone has its own copy of the variable.
- Game over
- Everything stops, and the player is told why.
Hand in
Share your game. Send the link and your table of four weapons to your teacher. Next lesson, you build them.