-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaddle.java
More file actions
56 lines (37 loc) · 824 Bytes
/
Paddle.java
File metadata and controls
56 lines (37 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.awt.Color;
import java.awt.Graphics;
public class Paddle {
public int paddleNumber;
public int x, y, width = 50, height = 250;
public int score;
public Paddle(Pong pong, int paddleNumber) {
this.paddleNumber = paddleNumber;
if (paddleNumber == 1) {
this.x = 0;
}
if (paddleNumber == 2) {
this.x = pong.width - width-7;
}
this.y = pong.height / 2 - this.height / 2;
}
public void render(Graphics g) {
g.setColor(Color.WHITE);
g.fillRect(x, y, width, height);
}
public void move(boolean up) {
int speed = 20;
if (up) {
if (y - speed > 0) {
y -= speed;
} else {
y = 0;
}
} else {
if (y + height + speed < Pong.pong.height) {
y += speed;
} else {
y = Pong.pong.height - height - speed;
}
}
}
}