- Learnt27 min · skill, streak, sudden death, start screen
- Basic25 min · finish the game
- Challenge 1–327 min · a keeper who learns, a record, an ending
- Extrabonus · they kick too
Review — where we got to 5 min
- The keeper rolls
(pick random (1) to (3))intodiveand glides to that side. - The verdict asks
<touching [Goalie v]?>first, then the goal test. - The Referee sets the match up, broadcasts kick off, and reads the score at the end.
Quick-fire
You aim at the left corner every time. How often does last lesson’s keeper dive left?
Reveal the answer
About one kick in three. It never looks at where you aim. Today it starts to — a little more every kick.
Today’s Topic 3 min
- A keeper whose skill grows every kick
- A streak, and a best streak the green flag never resets
- Sudden death when the match is level
- A start screen with a PLAY button
Learning outcome
By the end of this lesson you will be able to:
- Use pick random and a comparison to make something happen “sometimes”.
- Keep a record in a variable that no script resets.
- Add an extra round when a game ends level.
Learnt — finishing the game 27 min
1 · A keeper who gets better
A real keeper watches the kicker and sometimes reads the shot. Ours reads it (keeper skill) times in every 100. The skill starts at 20 and rises by 10 each kick.
First the keeper works out which third the shot is going to:
| aim x | shot side |
|---|---|
| less than −33 | 1 · left |
| −33 to 33 | 2 · middle |
| more than 33 | 3 · right |
Then it rolls a number from 1 to 100. If the roll is under the skill, it dives the right way. If not, it guesses like before.
if <(pick random (1) to (100)) < (20)> then
if <(pick random (1) to (100)) < (70)> then
- Make
shot sideandkeeper skill, For all sprites. - Change the old dive script’s hat to
when I receive [dive v]. Remove itsset [dive v] to (pick random (1) to (3)). - Build a new “think” script on
when I receive [kick v]. It ends withbroadcast [dive v] and wait. - Add
when I receive [start match v]withset [keeper skill v] to (20).
when I receive [kick v]
set [shot side v] to (2)
if <(aim x) < (-33)> then
set [shot side v] to (1)
end
if <(aim x) > (33)> then
set [shot side v] to (3)
end
if <(pick random (1) to (100)) < (keeper skill)> then
set [dive v] to (shot side)
else
set [dive v] to (pick random (1) to (3))
end
change [keeper skill v] by (10)
broadcast [dive v] and wait
when I receive [dive v]
if <(dive) = (1)> then
switch costume to [goalie-c v]
glide (0.4) secs to x: (-62) y: (10)
end
if <(dive) = (2)> then
switch costume to [goalie-e v]
glide (0.4) secs to x: (0) y: (10)
end
if <(dive) = (3)> then
switch costume to [goalie-d v]
glide (0.4) secs to x: (62) y: (10)
end
wait (1.2) seconds
switch costume to [goalie-a v]
go to x: (0) y: (10)
How to use this: Click the green flag and watch ten kicks. The keeper’s skill goes up by 10 each kick. Nothing to press.
2 · A streak, and a best streak
(streak) counts goals in a row. A save or a miss puts it back to 0. (best streak) is the highest streak ever.
when I receive [judge v]
if <touching [Goalie v]?> then
say [Saved!] for (1) seconds
set [streak v] to (0)
else
if <<<(aim x) > (-100)> and <(aim x) < (100)>> and <<(aim y) > (-25)> and <(aim y) < (85)>>> then
change [goals v] by (1)
change [streak v] by (1)
if <(streak) > (best streak)> then
set [best streak v] to (streak)
end
say [GOAL!] for (1) seconds
else
say [Miss!] for (1) seconds
set [streak v] to (0)
end
end
change [kicks left v] by (-1)
And one tiny script on the Ball: when I receive [start match v] then set [streak v] to (0). Look for the script that sets best streak to 0. There is none, on purpose.
How to use this: Click the green flag and watch the streak. Then click the flag again: streak starts at 0, but best streak stays.
3 · Sudden death
The other team has already taken their kicks. At the start, the Referee picks their score: (pick random (2) to (4)). Beat it to win.
- Make
their goals. Show its box on the Stage. - After five kicks, the Referee compares the scores.
- Level? Set
kicks leftto 1 and broadcast kick off again. That is sudden death: one kick, and it decides. - Then more goals wins. Anything else loses.
when I receive [start match v]
set [goals v] to (0)
set [kicks left v] to (5)
set [their goals v] to (pick random (2) to (4))
broadcast [kick off v]
wait until <(kicks left) = (0)>
if <(goals) = (their goals)> then
set [kicks left v] to (1)
broadcast [kick off v]
say [Sudden death! Score to win.] for (2) seconds
wait until <(kicks left) = (0)>
end
if <(goals) > (their goals)> then
say [You win the shootout!]
else
say [They win this time.]
end
4 · A start screen
A game should wait for the player. Two new sprites do it: a title, and a PLAY button.
when flag clicked
go to x: (0) y: (-60)
go to [front v] layer
show
when this sprite clicked
hide
broadcast [start match v]
when flag clicked
go to x: (0) y: (130)
show
when I receive [start match v]
hide
Now the match starts on start match, not the flag. The Referee’s hat changes to when I receive [start match v].
The Aim marker needs one change too:
when flag clicked
hide
when I receive [start match v]
set size to (70) %
go to [front v] layer
show
forever
go to [mouse-pointer v]
end
How to use this: Click the green flag, then click PLAY.
Basic — finish the game 25 min
Open last lesson’s project. Save a copy first, so you can always go back.
Step 1 — the keeper learns
- Make
shot sideandkeeper skill. - Split the keeper into think and dive, as in Learnt 1.
- Add the start match script that sets the skill to 20.
Step 2 — the streak
- Make
streakandbest streak. Show best streak. - Update the Ball’s verdict from Learnt 2.
- Add
when I receive [start match v]andset [streak v] to (0)on the Ball.
Step 3 — sudden death
- Make
their goals. Show it. - Rebuild the Referee’s script from Learnt 3.
Step 4 — the start screen
- Paint a title sprite and a PLAY button sprite. Words in big, clear letters.
- Give them the scripts from Learnt 4.
- Hide the Aim until start match.
Step 5 — who starts on the flag?
Only these should run on the green flag now:
- the title and PLAY showing,
- the Aim hiding,
- the keeper, the ball and the Referee going to their places.
Everything else waits for start match or kick off.
Step 6 — play three matches
Write down each result and your best streak after each one.
PLAY does nothing when I click it.
The Aim marker is on top of it, taking the click. Check it hides on the flag and only shows on start match.
The keeper saves everything by kick 3.
The skill starts too high, or grows too fast. 20 and 10 give a keeper who reads about six shots in ten by the last kick. Try 10 and 5 for an easier game.
Best streak goes back to 0 on the flag.
A set [best streak v] to (0) is hiding in a flag script somewhere. Search every sprite. There must be none.
Sudden death starts, but the meter does not move.
The second broadcast [kick off v] is missing. The meter stopped when kicks left reached 0, and needs telling to start again.
The game starts before I click PLAY.
A script still has when flag clicked where it should have when I receive [start match v]. Usually the Referee.
A keeper who learns
- The keeper’s skill starts low at the start of every match.
- It rises after every kick.
- A high skill means the keeper dives the right way more often.
- It still guesses wrong sometimes, even at the end.
A record that lasts
- streak counts goals in a row, and resets on a save or a miss.
- best streak keeps the highest streak ever.
- The green flag does not reset best streak.
- Saving and reopening the project does not reset it either.
Teacher note
Pupils often reset every variable on the flag out of habit. That is usually right, so ask them to say out loud why this one is different. A record is only a record if starting again does not wipe it.
An ending
- A start screen waits for PLAY.
- The other team’s score is chosen at random, 2 to 4, and shown.
- After five kicks, more goals win and fewer lose.
- Level means one sudden-death kick, and that kick decides.
Teacher reveal — testing the rare ending
Sudden death needs a tie, and a tie can take many matches. Show pupils how to force it: set their goals to a fixed number while testing, score exactly that many, and watch. Then put the pick random back. Testing a rare case on purpose is a real skill.
How to use this: Click the green flag, then click PLAY. Aim with the mouse and press the space bar to shoot. Beat the other team’s score.
They kick too
In a real shootout the teams take turns. Make the other team take a kick after each of yours — and end the match early when one side cannot catch up.
Teacher note — the catch-up test
You are out of reach when your goals plus the kicks you have left is still less than their goals. In blocks:
if <((goals) + (kicks left)) < (their goals)> then
say [They cannot be caught.] for (2) seconds
end
Summary 3 min
<(pick random (1) to (100)) < (keeper skill)>is true about “keeper skill” times in 100.- A script that works can keep its job. Give it a new hat instead of rewriting it.
- A record lasts as long as nothing resets it. Scratch saves it with the project.
- A tie can be broken with one more round: the same loop, started again.
- A start screen is a button that broadcasts, and scripts that wait for it.
- Skill
- How often the keeper reads the shot, out of 100.
- Streak
- Goals in a row, with no save or miss between.
- Record
- The best so far. Only beaten, never reset.
- Sudden death
- One more kick when it is level. That kick decides.
Ship it
Four lessons ago you pointed at a goal and clicked. Now you have a meter, a keeper who learns, a referee and a record. Play it cold: save, do something else for ten minutes, then play it following only what is on the screen. Fix anything that confused you.
If you have a Scratch account, share it on the Scratch website and send the link to your teacher.