NO PHYSICS ENGINE. EXPLICIT AABB, ONE RESOLVED HIT PER FRAME, VELOCITY MAGNITUDE ALWAYS PRESERVED.
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.
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.
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.
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.
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 }