CAB-01 · CANVAS 2D

BREAKOUT

8×4 grid · 400×600 field · fixed 60 Hz integration

Insert coin
3 lives · 32 bricks · 320 max
60 FPS · 2 substeps

Collision model

  1. Circle ↔ AABB. Nearest-point test on every brick, paddle included — radius 3 px, no bounding-box slop.
  2. Four candidate penetrations per contact: left, right, top, bottom.
  3. Smallest wins → that axis flips. Side hit flips dx, top/bottom hit flips dy.
  4. One resolution per substep. Contacts are scored, the deepest is resolved, then the loop breaks — a brick can never be hit twice in a frame.
  5. Speed is invariant. After every reflection the vector is re-normalised to the same magnitude with clamped minimums, so the ball can't stall, sink or tunnel.

The axis test

// deepest-overlap axis decides the response
const oL = ball.x + r - b.x,          // vs brick left
      oR = b.x + b.w - (ball.x - r),   // vs brick right
      oT = ball.y + r - b.y,
      oB = b.y + b.h - (ball.y - r);

const hz = Math.min(oL, oR), vt = Math.min(oT, oB);

if (hz < vt) {                       // horizontal
  ball.x += (oL < oR ? -hz : hz) + Math.sign(dx)*0.6;
  ball.dx = (oL < oR ? -1 : 1) * Math.abs(dx);
} else {                             // vertical
  ball.y += (oT < oB ? -vt : vt) + Math.sign(dy)*0.6;
  ball.dy = (oT < oB ? -1 : 1) * Math.abs(dy);
}
normalise();  // magnitude back to speed, |dy| ≥ 0.35
  • No straight-up serve
  • Paddle-edge english
  • Full-width pad bounds
  • Side-hit paddle rim
  • Substep anti-tunnel
  • Portrait + landscape