-
Notifications
You must be signed in to change notification settings - Fork 0
/
Paddle.java
66 lines (53 loc) · 823 Bytes
/
Paddle.java
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
57
58
59
60
61
62
63
64
65
66
package pong;
import java.awt.Color;
import java.awt.Graphics;
public class Paddle
{
public int paddleNumber;
public int x, y, width = 50, height = 150;
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;
}
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 = 15;
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;
}
}
}
}