Wall reflect
Left and right faces clamp the ball to x = r / x = 400 − r then invert dx. The HUD band at y = 28 is a solid ceiling — the ball can never hide behind the score readout.
HTML5 Canvas · 400×600 · 32 bricks · vanilla js, zero dependencies
Move the mouse or ← → · Space to launchDrag anywhere on screen · tap to launch
Explicit AABB · no physics engine
Left and right faces clamp the ball to x = r / x = 400 − r then invert dx. The HUD band at y = 28 is a solid ceiling — the ball can never hide behind the score readout.
Contact offset rel = (ball.x − paddleCentre) / 30 maps to a ±60° exit vector, rebuilt at constant magnitude: dx = v·sin θ, dy = −v·cos θ. Edge hits skim, dead-centre hits nearly verticalise.
Ball AABB is intersected against live bricks; the deepest hit is resolved and only that one is destroyed per substep. Penetration depth on each axis chooses the normal, so a top strike flips dy and a flank strike flips dx. The ball is then pushed flush to the brick face — no re-collision next frame, no tunnelling.
An accumulator runs the simulation at exactly 60 Hz while rendering at the display rate, with sub-stepping of ≤1.5 px per move so a 120 Hz phone and a throttled 30 Hz tab play identically. Velocity magnitude is renormalised after every bounce.
Ball under the canvas costs a life, re-seats the ball on the paddle and re-limits speed. Clearing all 32 bricks triggers the win card. Both cards carry an in-canvas restart button that is hit-tested with the same coordinate transform as the paddle.