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