Does (ballX, ballY) represent the center of the ball, or the top-left edge of the bounding square?
For one, this if statement looks somewhat "iffy":
if (ballY < 0 || ballY > (getHeight()-25) && ballX > paddleX && ballX < (paddleX +50))
Consider grouping the conditions with parenthesis more.. I assume the paddle appears on the top and bottom of the screen.
For blocks, you have to test:
Ball intersects block horizontally (at left OR right) AND vertically (at top OR bottom), therefore...
Horizontally:
If (ballX + ballWidth) >= blockX
Or if ballX <= (blockX + blockWidth)
And vertically:
If (ballY + ballHeight) >= blockY
Or if ballY <= (blockY + blockHeight)
The above considers the ball's bounding box... So, it treats the ball like a square, with (ballX, ballY) represening the top-left corner.
Helpful? Hmmm..
Reputation Points: 20
Solved Threads: 6
Junior Poster in Training
Offline 74 posts
since Nov 2005