1
0
Fork 0

Ball - hitsPaddle update

This commit is contained in:
rxbn_ 2019-12-07 17:24:39 +01:00
parent 8af4e653b2
commit 1a18e469ca
1 changed files with 6 additions and 3 deletions

View File

@ -105,14 +105,17 @@ public class Ball implements IBall {
Position posBall = this.getPosition();
// test balls y position against paddles y values
// paddles y values can be interpreted as a closed interval therefore if balls y position is in the interval, its true
boolean testPaddleY = (
(posBall.getY() <= posPaddle.getY()+paddle.getHeight() && posBall.getY() >= posPaddle.getY())
|| (posBall.getY()+Constants.BALL_DIAMETER >= posPaddle.getY() && posBall.getY() <= posPaddle.getY()+paddle.getHeight())
posPaddle.getY() <= posBall.getY() && posBall.getY() <= posPaddle.getY()+paddle.getHeight() ||
posPaddle.getY() <= posBall.getY()+Constants.BALL_DIAMETER && posBall.getY()+Constants.BALL_DIAMETER <= posPaddle.getY()+paddle.getHeight()
);
// test balls x position against paddles x values
// paddles x values can be interpreted as a closed interval therefore if balls x position is in the interval, its true
boolean testPaddleX = (
posBall.getX() >= posPaddle.getX() && posBall.getX() <= posPaddle.getX()+paddle.getWidth()
posPaddle.getX() <= posBall.getX() && posBall.getX() <= posPaddle.getX()+paddle.getWidth() ||
posPaddle.getX() <= posBall.getX()+Constants.BALL_DIAMETER && posBall.getX()+Constants.BALL_DIAMETER <= posPaddle.getX()+paddle.getWidth()
);
// if balls y position is in paddles y values, verify x position