diff --git a/src/main/java/PingPong/Paddle.java b/src/main/java/PingPong/Paddle.java index df6696d..34cad3f 100644 --- a/src/main/java/PingPong/Paddle.java +++ b/src/main/java/PingPong/Paddle.java @@ -7,9 +7,12 @@ public class Paddle extends Rectangle { int y1; int y2; int id; + int x; int yVelocity1; int yVelocity2; int speed = 10; + int width; + int height; Paddle(int x, int y, int width, int height, int id) { //super(x, y, width, height); @@ -25,18 +28,29 @@ public class Paddle extends Rectangle { } - public void pressed(KeyEvent e) { + public void released(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_W) { + setYDirection(0, 1); + } else if (e.getKeyCode() == KeyEvent.VK_S) { + setYDirection(0, 1); + } + + if (e.getKeyCode() == KeyEvent.VK_UP) { + setYDirection(0, 2); + } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { + setYDirection(0, 2); + } + move(); } - public void released(KeyEvent e) { + public void pressed (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) { diff --git a/src/main/java/PingPong/Score.java b/src/main/java/PingPong/Score.java index 6956bae..73b2ee1 100644 --- a/src/main/java/PingPong/Score.java +++ b/src/main/java/PingPong/Score.java @@ -9,6 +9,9 @@ public class Score extends Rectangle { public final int CENTER_DOT = 10; int player_1; int player_2; + + + public void draw(Graphics g) { g.setColor(Color.white); g.setFont(new Font("Consolas", Font.BOLD,50));