BREAKOUT

canvas 400 × 600 · 8×4 brick grid
60 FPS VANILLA JS AABB PHYSICS

Drag the playfield to steer · ← → on desktop

Under the hood

No physics engine, no libraries. Explicit swept-axis collision resolution against a fixed 8×4 grid, driven by a fixed timestep.

01AABB overlap testBall is expanded to a bounding box, then tested against every live brick. Overlap depth on each axis (ox, oy) picks the reflection axis; the previous frame position disambiguates corner hits.
02One hit per frameAmong all overlapping bricks only the shallowest-penetration brick is resolved, then the substep loop breaks — the ball can never be destroyed twice or get wedged between two cells. Position is pushed out along the collision normal.
03Paddle angle mappingContact offset rel = (ballX - paddleCenter) / (paddleW/2) maps to ±60°, and the vector is re-normalized to a constant magnitude of 3.4 px/step — edges bite hard, the middle plays safe.
04Fixed 60 Hz steprequestAnimationFrame accumulates real delta time and consumes it in 16.67 ms ticks, so 120 Hz displays and throttled tabs see identical ball speed. Two substeps per tick prevent tunnelling through 20 px bricks.
05Touch + mouse parityFinger position is mapped through getBoundingClientRect() into the 400-unit logical space, clamped to 0–340, then smoothed toward the target so fast swipes don't jitter the paddle.