Browse Source

update

main
fdai4616 2 years ago
parent
commit
753da4443b
  1. 11
      src/main/java/PingPong/GamePanel.java

11
src/main/java/PingPong/GamePanel.java

@ -43,7 +43,16 @@ public class GamePanel extends JPanel implements Runnable {
if(collisionChecker.didTouchTopOrBottomEdge(ball.y, FRAME_HEIGHT-BALL_DIAMETER)) {
ball.setYDirection(-ball.yVelocity);
}
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!
if (ball.yVelocity > 0)
ball.yVelocity++;
else
ball.yVelocity--;
ball.setXDirection(ball.xVelocity);
ball.setYDirection(ball.yVelocity);
}
}

Loading…
Cancel
Save