- Learnt28 min · a round, a referee, a match
- Basic24 min · the match
- Challenge 1–327 min · stale orbs, a banner, a time limit
- Extrabonus · a healing star
Review — firing and health 5 min
- An orb is a clone. It reads its fighter’s notes and flies until it hits something.
- A health bar has one costume for each tenth of health.
- A cooldown is the wait before you can fire again. We time it with the timer, not by counting.
Quick-fire
Right now, when a health bar reaches 0, what happens?
Reveal the answer
Nothing. Health just goes on down and the fight carries on. Nobody in the game is watching for the end. So today we add a sprite whose only job is to watch. It is the referee.
Today’s Topic 3 min
- A referee script that waits for a knock-out, when one fighter’s health runs out.
wins 1,wins 2, and first to two.- Resetting for a new round: health, positions and orbs.
- A
statethe fighters obey, like in Storm Flight.
Learning outcome
By the end of this lesson you will be able to:
- End a round when a condition is met, and score it.
- Reset everything a round leaves behind, even things still moving.
- Build a match out of repeated rounds.
Learnt — rounds 28 min
1 · A referee
Add a small sprite at the bottom of the arena. This is the referee. It does not fight. It watches:
wait until <<(health 1) < (1)> or <(health 2) < (1)>>
set [state v] to [over]
if <(health 1) < (1)> then
change [wins 2 v] by (1)
set [winner v] to [Giga]
else
change [wins 1 v] by (1)
set [winner v] to [Tera]
end
say (join [Round to ] (winner))
state is fight. So setting it to over stops the round straight away.How to use this: Click the green flag. Both fighters fire from their corners until one is out.
2 · A match
Wrap the round in a loop. It runs until someone has two wins. There is a reset between rounds:
repeat until <<(wins 1) = (2)> or <(wins 2) = (2)>>
wait until <<(health 1) < (1)> or <(health 2) < (1)>>
score the round :: custom
change [round v] by (1)
set [health 1 v] to (100)
set [health 2 v] to (100)
broadcast [new round v] and wait
broadcast [to your corners v] and wait
set [state v] to [fight]
end
say (join (winner) [ wins the match!])
score the round is part 1’s scoring, moved into a My Block. new round clears the orbs. to your corners moves the fighters home.How to use this: Click the green flag. Watch the rounds until somebody has two wins.
Basic — the match 24 min
Open your duel and make it a match.
Step 1 — the referee
- Add a small sprite at the bottom of the arena.
- Make
state,round,wins 1,wins 2andwinner. - Build the match loop from Learnt part 2.
Step 2 — the fighters obey
- Wrap each fighter’s loop body in
if <(state) = [fight]> then. - Add
when I receive [to your corners v]. Go to your start and face the other way.
Step 3 — the orbs obey
- Add
when I receive [new round v]→delete this cloneto both Orb sprites.
How to use this: Click the green flag. Player 1: W A S D and space. Player 2: arrows and L. First to two rounds.
The match ends in the first second.
wins 1 and wins 2 are not set to 0 at the start. An old score carries over from the last game.
Round 2 starts already over.
One health was not reset to 100, and the referee sees it still at 0.
A fighter is hit the moment round 2 begins.
An orb from round 1 is still flying. That is Challenge 1.
Stale orbs
Leave out the new round broadcast. Stop both fighters firing after round 1. Then read Tera’s health one second into round 2.
- Nobody fires in round 2.
- Tera’s health should be 100. Is it?
How to use this: Click the green flag. Round 1 is fought. Then round 2 begins with nobody firing. Watch the blue bar.
Teacher note
A reset has to cover everything the round left behind, including things still moving. The orbs were fired fairly in round 1 and land unfairly in round 2 — one delete this clone on new round ends it.
A banner between rounds
Before each round, the referee says “Round 2... ready...” for two seconds. Nobody may fire then.
- The state is
readywhile the banner shows. - Count the orbs fired during the banner.
How to use this: Click the green flag. Round 1 is fought. Watch what happens during the banner before round 2.
Teacher note
No fighter code changes: they already only act when the state is fight. A new state is free once every script asks the state first — the Storm Flight lesson, paying off again.
A time limit
Give each round six seconds. If nobody is out when time runs out, more health wins.
- A
time leftcounter that goes down a second at a time. - The round ends on a knock-out or at 0 seconds.
- Equal health is a draw.
How to use this: Click the green flag. Two slow-firing fighters and a six-second clock.
Teacher reveal — three endings
if <(health 1) > (health 2)> then
set [winner v] to [Tera]
else
if <(health 2) > (health 1)> then
set [winner v] to [Giga]
else
set [winner v] to [nobody - a draw]
end
end
The draw is the ending pupils forget, and the one that makes a match loop run for ever.
A healing star
Halfway through a round, a star appears in the centre. The first to touch it gets 30 health back.
- The star waits, appears, then waits to be touched.
- Healing never takes anyone above 100.
- It disappears once it is used.
How to use this: Click the green flag. Giga takes some hits. Then Giga walks to the star when it appears.
Teacher note
The cap at 100 is the bit to check: without it a player can stand on the star and go above full, and the health bar has no costume for 130.
Summary 5 min
- A referee waits for a knock-out. It sets the state and scores the round.
- A match is a loop of rounds until someone has two wins.
- A reset covers health, positions and anything still moving.
- Adding a new state, like a banner, is easy once every script checks the state.
- Round
- One fight, from full health to a knock-out or the time limit.
- Match
- A set of rounds. The first to win enough rounds wins the match.
- Referee
- A script whose only job is to notice when the game has changed.
- Reset
- Putting everything back as it was at the start.
Hand in
Save your match. Next lesson, the two copies of your fighter become one. Then every unfair bug we found in these lessons cannot happen.