From f8c27dbd867357fc3152cb3644014ebdf921c161 Mon Sep 17 00:00:00 2001 From: fdai4616 Date: Tue, 7 Feb 2023 23:53:59 +0100 Subject: [PATCH] update --- src/main/java/PingPong/Paddle.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/PingPong/Paddle.java b/src/main/java/PingPong/Paddle.java index eb5f8d0..d38778b 100644 --- a/src/main/java/PingPong/Paddle.java +++ b/src/main/java/PingPong/Paddle.java @@ -9,6 +9,7 @@ public class Paddle extends Rectangle { int id; int yVelocity1; int yVelocity2; + int speed = 1; Paddle(int x, int y, int width, int height, int id) { //super(x, y, width, height); @@ -29,6 +30,19 @@ public class Paddle extends Rectangle { } public void released(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_W) { + setYDirection(-speed, 1); + } else if (e.getKeyCode() == KeyEvent.VK_S) { + setYDirection(speed, 1); + } + + // Check if UP or DOWN key was pressed (for paddle 2) + if (e.getKeyCode() == KeyEvent.VK_UP) { + setYDirection(-speed, 2); + } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { + setYDirection(speed, 2); + } + move(); } public void move() {