From a7b12d0a7ce5c67cd05602cc329d7b9da27dc467 Mon Sep 17 00:00:00 2001 From: fdai4616 Date: Wed, 8 Feb 2023 00:03:11 +0100 Subject: [PATCH] update --- src/main/java/PingPong/Paddle.java | 20 +++++++++++++++++--- src/main/java/PingPong/Score.java | 3 +++ 2 files changed, 20 insertions(+), 3 deletions(-) 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));