Cabinet 01 · insert coin

Breakout

Thirty-two blocks, three lives and one sixty-pixel paddle standing between the ball and the void below. Pure canvas. No libraries.

Playfield
400 × 600 px
Grid
8 × 4 · 50 × 20
Ball
r3 · 3.6 → 4.0 px/f
Paddle
60 × 10 @ y580
Max score
320
attract mode — fps

Collision stack

Four explicit rules run once per fixed 1/60 s step. No physics engine, no swept solver — just tight AABB maths with penetration resolution and a single-winner pass that keeps the ball out of the brick walls.

01

Containment

r±R ∩ [x, x+50] × [y, y+20]

The ball's bounding box is tested against every live brick and the three walls. A broad-phase reject on the brick grid keeps the loop at 32 cheap comparisons per step.

02

Side resolution

px < py → flip dx : flip dy

Penetration depth on each axis decides which face was struck. The shallower axis is the one that crossed, so the ball ejects along the correct normal — never the wrong one.

03

Single hit

argmin(depth) · one per frame

When two bricks overlap the ball's box at once, only the deepest is resolved; the second is picked up next frame. Two flips in one step would cancel out and trap the ball inside the wall.

04

Exit guard

|dy| ≥ 1.05 · |dx| ≥ 0.55

After every bounce the velocity vector is re-normalised to constant magnitude, with minimum components that kill degenerate horizontal lock. Speed rises 3.6 → 4.0 as the wall thins.