Breakout

Canvas build · 400×600 · vanilla JS · no libraries

Ready — press space
Cabinet #08×04Field 400×600
Drag / arrows / touch

Under the cabinet

Explicit collision · no physics engine

01

Side-resolved AABB

The ball's bounding box is advanced, then tested against every live brick. Four penetration depths are measured and only the shallowest is honoured — that single value decides whether dx or dy flips, and the ball is snapped flush to that face so it can never be re-detected next step.

penL = right - brick.x penR = (brick.x+w) - left penT = bottom - brick.y penB = (brick.y+h) - top side = argmin(penL, penR, penT, penB)
02

Substepped, one hit per step

Movement splits into two half-steps, so the ball never travels further in a step than it is wide — no tunnelling through a 18 px brick. The loop breaks on the first hit, so one frame can never shred a whole row.

03

Angle from contact point

Paddle bounces read the offset of the hit: corners fire the ball wide, the middle keeps it near vertical. Magnitude is never altered by a bounce.

rel = clamp((ball.x - paddleCenter) / 30, -1, 1) dx = speed * sin(rel * 60deg) dy = -speed * cos(rel * 60deg)