- Learnt28 min · drops, powers, juice, levels
- Basic25 min · the whole game
- Challenge 1–327 min · random drops, a timer bar, catch
- Extrabonus · a level editor
Review — Brick Breaker III 5 min
- The
offset— ball x minus paddle x — set vx, so the player could aim. - Speed grew by 0.5 a hit, but never past 8: a ball faster than the paddle is unfair.
- A miss put the speed back to 5, and serve sent the ball straight up.
Quick-fire
In Bubble Popper (Level 3) twenty bubbles each floated at their own speed. What did each bubble need, that one shared speed variable could not give it?
Reveal the answer
A variable “for this sprite only”. Every clone gets its own copy. Today’s balls need exactly that: three balls, three different vxs.
Today’s Topic 3 min
- Power-ups from a list:
wide,slow,multi - Many balls as clones, each with its own vx and vy
- Juice: sparks and a shake
- Levels from save codes, and a win
Learning outcome
By the end of this lesson you will be able to:
- Drop a power-up chosen from a list, and give it an effect.
- Run many copies of one object, each keeping its own numbers.
- Move from level to level and end the game with a win.
Learnt — power-ups, polish and levels 28 min
1 · A ? brick drops a capsule
A new letter, ?, is a gold brick that breaks in one hit and drops a capsule. Which capsule? The next one in a list called power-ups.
| Item | Capsule | What it does |
|---|---|---|
wide | orange | The paddle grows to 150 % for 8 seconds. |
slow | blue | Every ball slows down. |
multi | pink | Two more balls. |
The list works like a bag: take the next one, and start again at the end. So every power comes round in turn — no three slows in a row.
define drop
change [turn v] by (1)
if <(turn) > (length of [power-ups v])> then
set [turn v] to (1)
end
set [next power v] to (item (turn) of [power-ups v])
set [drop x v] to ((-220) + ((40) * ((col) - (1))))
set [drop y v] to ((130) - ((20) * ((row) - (1))))
create clone of [Capsule v]
define hit brick
if <not <(tile) = [#]>> then
change [score v] by (10)
if <(tile) = [1]> then
write [.] :: custom
change [bricks left v] by (-1)
else
if <(tile) = [?]> then
write [.] :: custom
change [bricks left v] by (-1)
drop :: custom
else
write ((tile) - (1)) :: custom
end
end
end
when I start as a clone
set [my power v] to (next power)
switch costume to (my power)
go to x: (drop x) y: (drop y)
show
repeat until <(y position) < (-170)>
change y by (-3)
if <touching [Paddle v]?> then
set [power v] to (my power)
broadcast [power up v]
delete this clone
end
end
delete this clone
wide, slow and multi, like the list items. my power is for this sprite only.How to use this: Click the green flag to start it. Nothing else to press — a robot paddle breaks six ? bricks and tries to catch what falls.
2 · What each power does
Every power listens for power up and checks power. Wide belongs to the Paddle. It is timed with the timer, like Arena Duel’s cooldown — never by counting loops.
when I receive [power up v]
if <(power) = [wide]> then
set size to (150) %
set [wide until v] to ((timer) + (8))
end
wide until is above 0 and the timer has passed it, set size back to 100 % and wide until to 0.How to use this: Click the green flag to start it. Nothing else to press — every capsule here is wide.
Multi needs more than one ball — and three balls cannot share one vx. So the ball changes in two ways:
- Delete
vxandvy, and make them again for this sprite only. Now every clone has its own pair. - The original Ball hides and never plays. On
serveit makes one clone. Every ball in the game is a clone. ballscounts them. A ball that falls deletes itself, and only the last one costs a life.
when I receive [serve v]
set [balls v] to (1)
go to x: (paddle x) y: (-128)
set [vx v] to (2)
set [vy v] to (5)
create clone of [myself v]
when I receive [power up v]
if <<(power) = [multi]> and <(is clone) = (0)>> then
set [vx v] to (-4)
set [vy v] to (5)
create clone of [myself v]
set [vx v] to (4)
create clone of [myself v]
change [balls v] by (2)
end
when I start as a clone
set [is clone v] to (1)
show
repeat (15)
go to x: (paddle x) y: (-128)
end
forever
move ball :: custom
walls :: custom
... Lesson 31's paddle hit :: grey
if <(y position) < (-170)> then
change [balls v] by (-1)
if <(balls) = (0)> then
broadcast [lost v]
end
delete this clone
end
end
lost.How to use this: Click the green flag to start it. Nothing else to press — every capsule here is multi.
Slow is on the Ball too. It needs no is clone check: every ball should slow down.
when I receive [power up v]
if <(power) = [slow]> then
set [speed v] to (4)
set [vx v] to ((vx) * (0.6))
set [vy v] to ((vy) * (0.6))
end
3 · Juice: sparks and a shake
Juice is everything that makes a hit feel good but changes no rule. Two tricks:
when I start as a clone
go to x: (spark x) y: (spark y)
point in direction (pick random (-180) to (180))
show
repeat (10)
move (4) steps
change [ghost v] effect by (10)
end
delete this clone
when I receive [shake v]
repeat (8)
set [shake x v] to (pick random (-4) to (4))
set [shake y v] to (pick random (-3) to (3))
wait (0.03) seconds
end
set [shake x v] to (0)
set [shake y v] to (0)
The Stage itself cannot move. So each brick adds the wobble to its own spot, at the end of its forever loop:
go to x: (((-220) + ((40) * ((my col) - (1)))) + (shake x)) y: (((130) - ((20) * ((my row) - (1)))) + (shake y))
In hit brick, after change [bricks left v] by (-1) (in both places), add:
set [spark x v] to (x position)
set [spark y v] to (y position)
repeat (6)
create clone of [Spark v]
end
broadcast [shake v]
How to use this: Click the green flag to start it. Nothing else to press — a robot paddle plays, with sparks and shake on.
4 · Levels, and a win
Each level is a 72-letter save code — Lesson 30’s Extra — in a list called levels. unpack turns code number level into the wall.
- The Brick builds on a broadcast now:
build. Old clones hear it too, so they delete themselves first. Only the original (is clone= 0) builds. - A
Refereesprite waits untilbricks leftis 0, and sendsnext level. - The Brick adds 1 to
level. Past the last level, it sendswin.
when I receive [build v]
if <(is clone) = (1)> then
delete this clone
else
build wall :: custom
broadcast [serve v]
end
when I receive [next level v]
if <(is clone) = (0)> then
change [level v] by (1)
if <(level) > (length of [levels v])> then
broadcast [win v]
else
set [code v] to (item (level) of [levels v])
unpack :: custom
broadcast [build v]
end
end
when flag clicked
forever
wait until <<(bricks left) = (0)> and <(score) > (0)>>
broadcast [next level v]
wait until <(bricks left) > (0)>
end
when I receive [win v]
say (join [You win! Score ] (join (score) [.]))
score > 0 stops a win before the first wall is built.How to use this: Click the green flag to start it. Nothing else to press — a robot paddle plays two short levels under a steel roof.
Basic — the whole game 25 min
Open your Brick Breaker III project. This is a big build, so tick each step off.
Step 1 — new lists and variables
- Lists for all sprites:
power-ups(wide, slow, multi) andlevels. - Add three codes to
levels, one for each wall below — the six rows joined into one 72-letter code. - Variables for all sprites:
balls,turn,power,next power,drop x,drop y,wide until,shake x,shake y,spark x,spark y,level,code.
............ ............ ..?11??11?.. ..22222222.. ............ ............
............ .33......33. .2?2....2?2. .111.##.111. ............ ............
3..3..3..3.. .22.22.22.22 ?11?11?11?11 ............ #..........# ............
Step 2 — the sprites
- Brick: add
#and?costumes and anis clonevariable (this sprite only). Its green flag hides, setsis cloneto 0 andlevelto 1, unpacks level 1 and sendsbuild. Add the two scripts from Learnt section 4, and the shake to its clone loop. - Ball: remake
vxandvyfor this sprite only, addis clone, and build the serve, multi, slow and clone scripts from Learnt section 2. Adddropand the newhit brick. - Paddle: add the wide script and its timer check.
- Capsule, Spark, Shaker: new sprites, all hidden on the green flag.
- Referee: a heart in the corner. Its green flag sets
livesto 3 andscoreto 0.
Step 3 — losing a life, and the end
when I receive [lost v]
change [lives v] by (-1)
if <(lives) = (0)> then
broadcast [game over v]
else
set [speed v] to (5)
broadcast [serve v]
end
game over, and ball clones delete themselves on game over and win.How to use this: Click the green flag, then move the mouse left and right over the stage to slide the Paddle.
Every catch of multi gives far more than two balls.
The multi script is missing <(is clone) = (0)>. Every ball clone heard the broadcast and made two more.
The next level appears, but the old wall stays too.
The build script is missing its first half: clones must delete themselves.
All the balls move in exactly the same way.
vx and vy are still “for all sprites”. Delete them and make them again for this sprite only.
Surprise drops
The bag is fair, but players learn it. Add some surprise.
- The power is picked at random from the list.
- Any green brick that breaks has a 1-in-5 chance to drop one too.
- ? bricks still always drop.
How to use this: Click the green flag to start it. Nothing else to press — a robot paddle plays the arc’s wall, which has no ? bricks.
Teacher reveal
set [next power v] to (item (pick random (1) to (length of [power-ups v])) of [power-ups v])
replaces the first three blocks of drop. And when a green brick breaks:
if <(pick random (1) to (5)) = (1)> then
drop :: custom
end
A timer bar
A player cannot see when wide will run out. Draw it.
- While the paddle is wide, an orange bar sits along the bottom of the Stage.
- It starts 200 long and shrinks to nothing in 8 seconds.
- It is drawn with the Pen, not made of sprites.
How to use this: Click the green flag to start it. Nothing else to press — every capsule here is wide.
Teacher reveal
A hidden Bar sprite:
when flag clicked
hide
erase all
set pen size to (5)
forever
erase all
if <(wide until) > (0)> then
set pen color to [#F97316]
go to x: (-100) y: (-172)
pen down
go to x: ((-100) + ((200) * (((wide until) - (timer)) / (8)))) y: (-172)
pen up
end
wait (0) seconds
end
(wide until) − (timer) is the time left; ÷ 8 makes it a fraction. Boss Tower’s health bar used the same sum.
A catch power
Add a fourth power: catch.
- A green
catchcapsule. Add it to the list and to the Capsule’s costumes. - After it, the next ball that hits the paddle sticks there.
- It rides the paddle until the space bar, then flies off with its aimed vx.
How to use this: Click the green flag, then move the mouse to slide the Paddle. When a ball sticks to it, click the stage once and press the space bar to let go.
Teacher reveal
A variable catching. The Paddle sets it to 1 when power is catch. In the ball clone’s forever, straight after the paddle hit:
if <<(catching) = (1)> and <<touching [Paddle v]?> and <(vy) > (0)>>> then
repeat until <key (space v) pressed?>
go to x: (paddle x) y: (-128)
end
set [catching v] to (0)
end
vy > 0 means the paddle hit has just happened. The aimed vx is already set, so the ball leaves the way it would have.
A level editor
Tile Maker had a click-to-paint editor. Give Brick Breaker one.
- The game starts with an empty wall and a cursor that snaps to the cell under the mouse.
- A click changes that cell’s letter:
.→1→2→3→#→?→. - The wall redraws straight away. Space starts the game on your level.
How to use this: Click the green flag, then click cells on the wall to paint bricks. Click the stage once and press the space bar to play your level, moving the mouse to slide the Paddle.
Teacher reveal
An Editor sprite with its own copies of brick at and write. The Brick only sends serve once editing is 0.
when flag clicked
show
go to [front v] layer
set [editing v] to (1)
forever
brick at (mouse x) (mouse y) :: custom
if <<(row) > (0)> and <(row) < (7)>> then
go to x: ((-220) + ((40) * ((col) - (1)))) y: ((130) - ((20) * ((row) - (1))))
if <<mouse down?> and <(editing) = (1)>> then
set [next v] to (item (((item # of (tile) in [palette v]) mod (6)) + (1)) of [palette v])
write (next) :: custom
broadcast [build v]
wait until <not <mouse down?>>
end
end
end
when [space v] key pressed
if <(editing) = (1)> then
set [editing v] to (0)
hide
broadcast [serve v]
end
The wait until stops one long click painting six times.
Summary 5 min
- A ? brick drops the next power from a list. A capsule clone carries it down.
- Many balls means clones, and vx and vy for this sprite only.
- Juice — sparks and shake — changes how a game feels, not its rules.
- Levels are save codes in a list. Clear the last one and you win.
- Power-up
- Something you collect that changes the rules for a while.
- Juice
- Effects that make actions feel good without changing the rules.
- Bag
- A list you take items from in turn, so each one comes round.
Hand in
Save your Brick Breaker — the arc is finished. Next lesson, a new arcade game: Kart Racer, where the car turns with sine and cosine.