Anonymous
public text v1 · immutableint btop = ball.y - ball.radius
int bbot = ball.y + ball.radius
int bleft = ball.x - ball.radius
int bright = ball.x + ball.radius
int brickcenterx = (brick.right + brick.left)/2
int brickcentertop = (brick.top + brick.bottom)/2
if ( btop <= brick.bottom && bbot >= brick.top
&& bleft <= brick.right && bright >= brick.left ) {
int deltax = abs(brickcenterx - ball.x)
int deltay = abs(brickcentery - ball.y)
if (deltax > deltay)
ball.vx = -ball.vx
else
ball.vy = -ball.vy
}