-
Notifications
You must be signed in to change notification settings - Fork 0
/
Paddle.java
84 lines (64 loc) · 1.47 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
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class Paddle extends ColorShape{
private static int speed;
private static int xPos = 250 ;
private static final int height = 10;
private static int width = 85;
private static final int yPos = Parameters.PADDLE_START_Y;
private static Rectangle2D.Double paddle = new Rectangle2D.Double(xPos,yPos,width,height);
public Paddle() {
super(paddle);
speed = 0;
super.setFillColor(Color.BLACK);
super.setBorderColor(Color.BLACK);
}
public static void move() {
if (xPos <=-1) {
xPos = 0;
}
else if (xPos >= Parameters.GAME_WIDTH-width) {
xPos = Parameters.GAME_WIDTH-width-1;
}
else {
xPos += speed;
paddle.setRect(xPos,yPos,width,height);
}
}
public static void setSpeed(int newSpeed){
speed = newSpeed;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getX() {
return xPos;
}
public void bigWidth() {
width += 20;
}
public void smallWidth() {
width -= 20;
}
public static Rectangle2D.Double getShape() {
return paddle;
}
public static void moveR() {
speed = (Parameters.PADDLE_SPEED);
}
public static void moveL() {
speed = (-1*Parameters.PADDLE_SPEED);
}
public void moveS() {
speed = 0;
}
public void paint(Graphics2D brush) {
brush.draw(paddle);
brush.setColor(Color.BLACK);
brush.fill(paddle);
}
}