/
Paddle.java
89 lines (77 loc) · 1.25 KB
/
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
*
* Paddle.java - Creates a Paddle for AirPong
*
* @author Brian Etzel
* @version 1.0
*/
import java.awt.Graphics;
import java.awt.Color;
public class Paddle
{
//private final int X = 675;
private final int PADDLE_HEIGHT = 50;
private final int PADDLE_WIDTH = 10;
private int x;
private int y = 250;
private int yVelocity = 0;
/**
* Constructor for Paddle Class
*/
public Paddle(int paddlePos)
{
this.x = paddlePos;
}
/**
* Updates the location of the paddle on the screen
*/
public void update()
{
y = y + yVelocity;
}
/**
* Paints the paddle
*/
public void paint(Graphics g)
{
g.setColor(Color.BLUE);
g.fillRect(x, y, PADDLE_WIDTH, PADDLE_HEIGHT);
}
/**
* Updates the movement velocity of a paddle
*
* @param newVelocity - The velocity to be updated
*/
public void updateVelocity(int newVelocity)
{
yVelocity = newVelocity;
}
/**
* Returns the Y location of Paddle
*/
public int getY()
{
return this.y;
}
/**
* Returns the X location of Paddle
*/
public int getX()
{
return this.x;
}
/**
* Returns the Paddle Height
*/
public int getPaddleHeight()
{
return this.PADDLE_HEIGHT;
}
/**
* Returns the Paddle width
*/
public int getPaddleWidth()
{
return this.PADDLE_WIDTH;
}
}