|
|
@ -45,7 +45,7 @@ public class GamePanel extends JPanel implements Runnable { |
|
|
|
} |
|
|
|
if(collisionChecker.didTouchPaddle(ball, new Rectangle(paddle_1.x, paddle_1.y1, paddle_1.width, paddle_1.height))) { |
|
|
|
ball.xVelocity = Math.abs(ball.xVelocity); |
|
|
|
ball.xVelocity++; // increasing ball's speed! |
|
|
|
ball.xVelocity++; |
|
|
|
if (ball.yVelocity > 0) |
|
|
|
ball.yVelocity++; |
|
|
|
else |
|
|
@ -53,6 +53,16 @@ public class GamePanel extends JPanel implements Runnable { |
|
|
|
ball.setXDirection(ball.xVelocity); |
|
|
|
ball.setYDirection(ball.yVelocity); |
|
|
|
} |
|
|
|
if(collisionChecker.didTouchPaddle(ball, new Rectangle(paddle_2.x, paddle_2.y2, paddle_2.width, paddle_2.height))) { |
|
|
|
ball.xVelocity = Math.abs(ball.xVelocity); |
|
|
|
ball.xVelocity++; |
|
|
|
if (ball.yVelocity > 0) |
|
|
|
ball.yVelocity++; |
|
|
|
else |
|
|
|
ball.yVelocity--; |
|
|
|
ball.setXDirection(-ball.xVelocity); |
|
|
|
ball.setYDirection(ball.yVelocity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|