Collision model
Circle → AABB nearest-point test. The candidate with the smallest squared distance wins, so a multi-brick contact resolves exactly one collision per sub-step. The contact normal picks the axis, the ball is pushed out to the brick face, and a one-frame lock on the brick id stops re-collision inside the same tick.
const nx = clamp(ball.x, b.x, b.x + b.w); const ny = clamp(ball.y, b.y, b.y + b.h); if (dx*dx + dy*dy <= r*r) { |dx| > |dy| ? vx = sign(dx)*|vx| : vy = sign(dy)*|vy|; }