From 753da4443b731424d1688c034535c354624987f0 Mon Sep 17 00:00:00 2001 From: fdai4616 Date: Wed, 8 Feb 2023 20:45:00 +0100 Subject: [PATCH] update --- src/main/java/PingPong/GamePanel.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/PingPong/GamePanel.java b/src/main/java/PingPong/GamePanel.java index c95c098..8dbf850 100644 --- a/src/main/java/PingPong/GamePanel.java +++ b/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); + } }