Browse Source

update

main
fdai4616 2 years ago
parent
commit
a7b12d0a7c
  1. 20
      src/main/java/PingPong/Paddle.java
  2. 3
      src/main/java/PingPong/Score.java

20
src/main/java/PingPong/Paddle.java

@ -7,9 +7,12 @@ public class Paddle extends Rectangle {
int y1; int y1;
int y2; int y2;
int id; int id;
int x;
int yVelocity1; int yVelocity1;
int yVelocity2; int yVelocity2;
int speed = 10; int speed = 10;
int width;
int height;
Paddle(int x, int y, int width, int height, int id) { Paddle(int x, int y, int width, int height, int id) {
//super(x, y, width, height); //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) { if (e.getKeyCode() == KeyEvent.VK_W) {
setYDirection(-speed, 1); setYDirection(-speed, 1);
} else if (e.getKeyCode() == KeyEvent.VK_S) { } else if (e.getKeyCode() == KeyEvent.VK_S) {
setYDirection(speed, 1); setYDirection(speed, 1);
} }
// Check if UP or DOWN key was pressed (for paddle 2)
if (e.getKeyCode() == KeyEvent.VK_UP) { if (e.getKeyCode() == KeyEvent.VK_UP) {
setYDirection(-speed, 2); setYDirection(-speed, 2);
} else if (e.getKeyCode() == KeyEvent.VK_DOWN) { } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {

3
src/main/java/PingPong/Score.java

@ -9,6 +9,9 @@ public class Score extends Rectangle {
public final int CENTER_DOT = 10; public final int CENTER_DOT = 10;
int player_1; int player_1;
int player_2; int player_2;
public void draw(Graphics g) { public void draw(Graphics g) {
g.setColor(Color.white); g.setColor(Color.white);
g.setFont(new Font("Consolas", Font.BOLD,50)); g.setFont(new Font("Consolas", Font.BOLD,50));

Loading…
Cancel
Save