- Learnt28 min · orbs as clones, hits and health bars
- Basic24 min · the duel
- Challenge 1–327 min · own goals, a cooldown, cover
- Extrabonus · knockback
Review — two players, one keyboard 5 min
- Each fighter has its own loop and its own keys.
walkis move-ask-undo on x and then on y.- Two copies of the same code must stay the same — except where they must not.
Quick-fire
A fighter will fire orbs. How can a clone of an Orb sprite know where the fighter is and which way it is facing, when the fighter is a different sprite?
Reveal the answer
The fighter leaves a note. Just before making the clone, it copies its x, y and direction into variables — shot 1 x, shot 1 y, shot 1 dir — and the new orb reads them the moment it starts.
Today’s Topic 3 min
- Firing:
create clone of (Orb 1 v)from another sprite - An orb that flies until a wall, a pillar or an enemy
health 1,health 2, and a bar with a costume per tenth- A cooldown kept by the timer
Learning outcome
By the end of this lesson you will be able to:
- Fire clones from one sprite that belong to another.
- Show a number as a picture — a health bar.
- Limit how fast something can happen, using time rather than counting.
Learnt — firing 28 min
1 · An orb is a clone
Tera has its own Orb sprite, Orb 1, hidden. Firing is a My Block on Tera:
define fire
if <(timer) > (next shot)> then
set [next shot v] to ((timer) + (0.4))
set [shot 1 x v] to (x position)
set [shot 1 y v] to (y position)
set [shot 1 dir v] to (direction)
create clone of (Orb 1 v)
end
next shot. Challenge 2 shows why it is not a count.
when I start as a clone
go to x: (shot 1 x) y: (shot 1 y)
point in direction (shot 1 dir)
show
repeat until <touching color [#8B5A3C]?>
move (8) steps
if <touching (Giga v)?> then
change [health 2 v] by (-10)
delete this clone
end
end
delete this clone
How to use this: Click the green flag. Tera fires three orbs along the top of the arena.
2 · A hit, and a health bar
The orb above already takes ten off health 2 when it touches Giga. To show it, a Bar sprite has eleven costumes — red 0 to red 10 — and wears the one that matches:
forever
switch costume to (join [red ] (round ((health 2) / (10))))
end
How to use this: Click the green flag. Tera fires three orbs straight at Giga; watch the red bar.
Basic — the duel 24 min
Open your face-off and give both fighters something to fire.
Step 1 — the orbs
- Draw a small round orb — blue for Tera, red for Giga — as two sprites,
Orb 1andOrb 2. - Both hidden when the flag is clicked.
- Build Orb 1’s clone script from Learnt part 1; Orb 2’s is the same, reading
shot 2and hurting Tera.
Step 2 — fire
- Make
health 1,health 2and the sixshotvariables, for all sprites. Set both healths to 100. - Give each fighter a
next shotvariable, for this sprite only, and thefireblock. - Space fires for Tera; L fires for Giga.
Step 3 — the bars
- Paint a bar with eleven costumes, from empty to full, on the same canvas.
- One bar top-left for Tera, one top-right for Giga.
How to use this: Click the green flag. Player 1: W A S D and space. Player 2: arrows and L. Fire at each other.
The orbs all come out of the middle of the Stage.
The clone reads the shot variables before the fighter has set them. Set them first, then clone.
The health bar never changes.
The costume names do not match the join exactly — red 7, with a space. Check every costume name.
Firing hurts the fighter who fired.
That is Challenge 1.
Holding the fire key makes a solid line of orbs.
There is no cooldown yet, or it is being counted instead of timed. That is Challenge 2.
The own goal
Make Tera’s orb hurt any fighter it touches, and fire three at Giga. Count who gets hit.
- The orb checks for Tera as well as Giga.
- Keep a count of hits on each.
- Explain the result, then put it right.
How to use this: Click the green flag. Tera fires three orbs; watch the blue bar, not the red one.
Teacher note
The orb is born exactly where the fighter stands, so its first question — am I touching a fighter? — is always yes. Every shooter in every game has to know who fired, and not hit them. Lesson 3-44 meets this again when both fighters share one Orb sprite.
A cooldown
Hold fire for two seconds, with and without a cooldown of 0.4 seconds.
- The cooldown uses
(timer)and anext shottime. - Count the orbs each way.
How to use this: Click the green flag. Both fighters hold fire for two seconds — only one has a cooldown.
Teacher note — why not count ticks?
The first version of this demo counted a cooldown variable down by one every tick — and fired twice as often as it should. A loop that draws nothing can run many times in one frame, so “12 ticks” is not a fixed length of time. The timer is. Any rule that means “not more often than every so many seconds” belongs on the timer.
Cover
Fire four orbs at Giga hiding behind a pillar, then four more with Giga in the open.
- Nothing new to build — the orb already stops at the wall colour.
- Count hits behind the pillar and in the open.
How to use this: Click the green flag. Four shots at Giga behind a pillar, then four in the open.
Teacher note
A good arena is a design question, not a code one: too much cover and nobody gets hit; too little and the first to fire wins. Let pairs trade arenas and report back.
Knockback
A hit should shove the fighter backwards — but never through a wall.
- The orb sets
knocked 2to 6 when it hits Giga. - Giga’s loop: while
knocked 2is above 0,walkaway and count it down.
How to use this: Click the green flag. Tera fires three orbs at Giga, who starts near the middle.
Teacher note
Knockback changes the duel more than it looks: a hit now also costs ground, and a fighter pinned against a wall cannot be pushed further. Watch who starts using that.
Summary 5 min
- A fighter fires by leaving notes in variables and cloning its own Orb sprite.
- An orb flies until the wall colour, a pillar or the enemy, then deletes itself.
- A bar with a costume per tenth draws health as a picture.
- An orb must know who fired it, or it hits its own shooter.
- Cooldowns belong on the timer, not on a counter.
- Projectile
- Something fired that travels on its own — here, an orb.
- Health bar
- A picture that shows a number at a glance.
- Cooldown
- The wait before something can happen again.
- Friendly fire
- Being hit by your own side’s shot.
Hand in
Save your duel. Next lesson it becomes a match: rounds, a referee and a winner.