- Learnt27 min · the dive, the save, the match
- Basic25 min · a keeper and a referee
- Challenge 1–327 min · guess, save, five kicks
- Extrabonus · a keeper who reads soft shots
Review — where we got to 5 min
(power)swings from 0 to 100 and back, because(step)flips at each end.- SPACE stops the meter. The meter saves the aim and broadcasts the kick.
- Above 85 flies over the bar. Below 30 stops short.
Quick-fire
You press SPACE at power 86 and aim at the bottom corner. Where does the ball go?
Reveal the answer
Over the bar. The power rule sets (aim y) to 150 whatever you aimed at. Only the x of your aim is kept.
Today’s Topic 3 min
- A keeper who picks a side with pick random
- A save: the keeper touching the ball when it lands
- A verdict script that does one job
- A five-kick match with a scoreboard and a referee
Learning outcome
By the end of this lesson you will be able to:
- Use pick random to make a sprite choose between three actions.
- Use touching to decide what happened when two sprites meet.
- Run a game for a fixed number of turns, then report the result.
Learnt — the keeper decides 27 min
1 · Pick a side
A real keeper guesses. They dive left, stay in the middle, or dive right, and hope. Ours does the same with (pick random (1) to (3)).
| dive | Side | Costume | Glide to |
|---|---|---|---|
| 1 | left | goalie-c | x: −62 |
| 2 | middle | goalie-e | x: 0 |
| 3 | right | goalie-d | x: 62 |
- Add the Goalie sprite from the library. Set its size to 60. Put it at
go to x: (0) y: (10). - Make a variable
dive, For all sprites. - Start a script with
when I receive [kick v]. The meter already sends it. - Add
set [dive v] to (pick random (1) to (3)). - Add three ifs, one per row of the table. Each switches costume, then glides.
- Wait, then go back to the middle, standing up.
when I receive [kick v]
set [dive v] to (pick random (1) to (3))
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. A kick happens every second and a half, and the keeper picks a side each time. Nothing to press.
2 · Saved!
When the ball lands, it checks the keeper first. Touching the Goalie means saved. Only if it is not touching do we ask the goal question.
That makes the ball’s script long. So we split it in two: one script kicks, one script judges.
when I receive [kick v]
if <(power) > (85)> then
set [aim y v] to (150)
end
if <(power) < (30)> then
set [aim y v] to (-70)
end
glide (0.6) secs to x: (aim x) y: (aim y)
broadcast [judge v] and wait
go to x: (0) y: (-118)
when I receive [judge v]
if <touching [Goalie v]?> then
say [Saved!] for (1) seconds
else
if <<<(aim x) > (-100)> and <(aim x) < (100)>> and <<(aim y) > (-25)> and <(aim y) < (85)>>> then
change [goals v] by (1)
say [GOAL!] for (1) seconds
else
say [Miss!] for (1) seconds
end
end
change [kicks left v] by (-1)
- Change the ball’s glide to
0.6seconds. - Drag the goal if / else out of the kick. Put
broadcast [judge v] and waitwhere it was. - Start a new ball script,
when I receive [judge v]. - Add
if <touching [Goalie v]?> thenwith an else. Saved goes in the top half. - Drop the old goal if / else into the bottom half.
How to use this: Click the green flag and watch eight kicks at random spots. The keeper guesses a side each time. Nothing to press.
3 · A five-kick match
A new sprite runs the match: the Referee from the library. It sets the scores, starts the meter, waits, and reads out the result.
when flag clicked
switch costume to [referee-a v]
set [goals v] to (0)
set [kicks left v] to (5)
say [Five kicks. Good luck!] for (2) seconds
broadcast [kick off v]
wait until <(kicks left) = (0)>
switch costume to [referee-c v]
say (join (goals) [ goals out of 5!])
referee-c is the costume blowing the whistle.The meter changes in two places:
- Its hat becomes
when I receive [kick off v]. - Its
foreverbecomesrepeat until <(kicks left) = (0)>. It stops by itself after the fifth kick.
when I receive [kick off v]
set [power v] to (0)
set [step v] to (2)
repeat until <(kicks left) = (0)>
repeat until <key [space v] pressed?>
change [power v] by (step)
if <(power) > (99)> then
set [step v] to (-2)
end
if <(power) < (1)> then
set [step v] to (2)
end
set size to (power) %
end
set [aim x v] to (mouse x)
set [aim y v] to (mouse y)
broadcast [kick v] and wait
end
Basic — a keeper and a referee 25 min
Open last lesson’s project. Aim, Arrow, Frame and the swing all stay.
Step 1 — the Goalie
- Add Goalie. Size 60. Make
dive. - A flag script:
switch costume to [goalie-a v]andgo to x: (0) y: (10). - The dive script from Learnt 1.
- Play five kicks. Does the keeper ever go to all three places?
Step 2 — kick and verdict
- Make
kicks left. - Split the ball’s kick into the two scripts from Learnt 2.
- Shoot straight at the keeper’s side a few times. Watch for Saved!.
Step 3 — the Referee
- Add Referee from the library. Size 60, at
go to x: (-190) y: (-110). - Build its script from Learnt 3.
- Take
set [goals v] to (0)off the ball. The Referee owns it now.
Step 4 — the meter waits for kick off
- Change the Power sprite’s hat and its outer loop.
- Play a whole match. The meter should stop after kick five.
The keeper dives to two places at once, or not at all.
(pick random (1) to (3)) is inside the ifs instead of in dive. Roll once, store it, then test the stored number.
Every shot at the keeper still says GOAL!.
The touching check is in the else, or it comes after the goal test. The keeper must be asked about first.
Kicks left goes down by two each kick.
change [kicks left v] by (-1) is inside both halves of an if, and also at the bottom. It belongs once, at the very end of the verdict.
The meter never starts.
Its hat still says when flag clicked, or the Referee’s broadcast [kick off v] is missing. Check both use the same message name.
The Referee reads the score one kick early.
Check the Referee sets kicks left to 5, not 4. And check the meter does not also change it.
The keeper picks a side
- At every kick, the keeper goes left, middle or right.
- You cannot tell in advance which.
- The costume leans the way the keeper goes.
- After each kick the keeper stands up in the middle again.
Saved!
- A ball that lands on the keeper says Saved!.
- A save never counts as a goal.
- A ball the keeper missed is judged the old way: goal or miss.
goals reads exactly 3.Teacher note
Try the ball at 0.3 seconds and the keeper at 0.4. Saves almost vanish, because the ball lands before the keeper arrives. It is a good way to show that two scripts running “at the same time” still have a timing between them.
Five kicks
goalsandkicks leftshow on the Stage.- The Referee starts the match and the meter only then begins.
- Every kick, saved or not, takes one off kicks left.
- After five, the meter stops and the Referee says the score.
Teacher reveal — who owns what
Ask each pupil to point at the sprite that owns each variable. The Referee sets goals and kicks left; the Ball changes them; the Power sprite and the Referee only read kicks left. A pupil who can say that out loud can debug the match alone.
How to use this: Click the green flag and click the Stage once. Aim with the mouse and press the space bar to shoot. Five kicks, then the Referee gives the score.
A soft shot is easy to read
A slow ball gives a keeper time to watch it. Make the keeper stop guessing when the power is low.
How to use this: Click the green flag and click the Stage once. Aim, then press the space bar. Try a soft shot, under 50, and watch the keeper.
Teacher reveal — two plans for the keeper
when I receive [kick v]
if <(power) < (50)> then
switch costume to [goalie-e v]
glide (0.4) secs to x: (aim x) y: (10)
else
broadcast [guess v] and wait
end
wait (1.2) seconds
switch costume to [goalie-a v]
go to x: (0) y: (10)
when I receive [guess v]
set [dive v] to (pick random (1) to (3))
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
Summary 3 min
(pick random (1) to (3))makes a choice. Store it once, then test the stored number.<touching [Goalie v]?>decides a save, so ask it first.- A long script splits well: one script kicks, one judges.
- A match is a count down. The meter runs until kicks left is 0.
- Set things up, then broadcast go. The flag starts everything at once.
- Random
- Chosen by chance. You cannot know it before it happens.
- Save
- The keeper touching the ball when it lands.
- Verdict
- The decision after each kick: saved, goal or miss.
- Match
- A fixed number of turns, then a result.
Next lesson: a keeper who learns, sudden death, and a start screen.