CANVAS 2D · VANILLA JS // BUILD 1.0 // REQUESTANIMATIONFRAME @60
BREAKOUT 32 BRICKS / 3 LIVES / 320 POINTS · DRAG OR ARROW THE PADDLE
FIELD 400×600 GRID 8×4 @ 50×20 BALL r=3 SPEED 3.4 px/f INPUT TOUCH+MOUSE+KEYS
400 × 600 · CANVAS 2D INSERT COIN
MOBILE: drag anywhere on the screen · DESKTOP: mouse or ← → · LAUNCH: click / tap / space

COLLISION LOGIC

NO PHYSICS ENGINE. EXPLICIT AABB, ONE RESOLVED HIT PER FRAME, VELOCITY MAGNITUDE ALWAYS PRESERVED.

  1. 01

    Walls

    Left / right clamp the ball to x = ±r and negate dx; the ceiling sits at the HUD divider y = 44 and negates dy. Wall hits never change speed.

  2. 02

    Paddle

    Offset (ball.x - paddleCenter) / 30 maps to a ±60° exit angle, so edge hits travel wide and centre hits return nearly vertical. Paddle velocity adds a little english, then the vector is renormalised.

  3. 03

    Bricks

    Penetration on each axis is measured against every alive brick; only the shallowest axis flips — small ox means a side hit (flip dx), small oy means top/bottom (flip dy). Of all candidates, only the single deepest-overlap brick resolves, so multi-brick contacts never double-bounce.

  4. 04

    Anti-stick lock

    After a hit the ball is pushed clear of the brick by the penetration depth and the brick id is locked for 3 frames — re-entry into the same cell cannot re-trigger. A guard keeps |dy| ≥ 0.18·speed so the ball never locks into a horizontal loop.

  5. 05

    Bottom

    Below y > 600 + r a life is spent, the board is kept, and the ball re-docks on the paddle for a fresh serve (auto-launch after ~1.1 s so thumbs never stall).

// fixed 16.66ms step — same feel at 60Hz and 120Hz
for (b in bricks) if (b.alive && !locked(b)) {
  ox = min(ball.r, b.right) - max(ball.l, b.left);   // x overlap
  oy = min(ball.b, b.bottom) - max(ball.t, b.top);   // y overlap
  if (ox > 0 && oy > 0) candidate(b, ox < oy ? "X" : "Y", min(ox, oy));
}
hit = closest(candidate);
if (hit) {
  axis === "X" ? (dx = -sign(dx), x -= nx * ox)
             : (dy = -sign(dy), y -= ny * oy);
  lock(hit.id, 3);           // no re-collision this frame
  hp--; if (hp <= 0) { alive = false; score += 10; burst(); }
  normalize(v, SPEED);       // magnitude preserved, always
}
RENDER
Canvas 2D · DPR ≤2
BRICKS
32 · 8×4 · 50×20
PADDLE
60×10 @ y580 · x 0–340
SERVE
(2, −2.8) normalised
PER BRICK
+10 pts · max 320
LIVES
3 · lose at 0