All pastes #800744 Raw Edit

Anonymous

public text v1 · immutable
#800744 ·published 2007-11-28 18:38 UTC
rendered paste body
int 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
}