01
Side-resolved AABB
The ball's bounding box is advanced, then tested against every live brick. Four penetration depths are measured and only the shallowest is honoured — that single value decides whether dx or dy flips, and the ball is snapped flush to that face so it can never be re-detected next step.
penL = right - brick.x
penR = (brick.x+w) - left
penT = bottom - brick.y
penB = (brick.y+h) - top
side = argmin(penL, penR, penT, penB)