forked from imruahmed/Brick-Breaker-Simple-Game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Paddle.java
112 lines (79 loc) · 2.04 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Paddle{
//Paddle class
//Holds all information of the game paddle
private int x, y, width; //Holds x and y position, and width of paddle
private String pUp; //Holds paddle's current powerup in use
public Paddle(int x, int y){
//basic paddle set up
this.x = x;
this.y = y;
width = 60;
pUp = "";
}
public void move(boolean[] keys){
//Moves paddle left and right according to keys pressed and released
if(keys[KeyEvent.VK_LEFT]){
if(this.getX() > 0) {
this.setX(this.getX() - 7);
}
}
if(keys[KeyEvent.VK_RIGHT]){
if(this.getX() + 60 < 500) {
this.setX(this.getX() + 7);
}
}
}
public void powerUse(int lives, Ball b){
//Allows paddle to user powerups
if (pUp.equals("expand")){ //Makes paddle bigger
width = 90;
}
else if (pUp.equals("shrink")){ //Makes paddle smaller
width = 40;
}
else if(pUp.equals("life")){ //Gives user an extra life
lives += 1;
}
else if(pUp.equals("fast")){ //Makes ball speed up
b.setDY(b.getDY() * 1.5 );
}
else if (pUp.equals("slow")){ //Makes ball slow down
b.setDY(b.getDY() * 0.5 );
}
else{ //Returns paddle to original state
width = 60;
}
}
//Gets width of paddle
public int getWidth(){
return width;
}
//Gets x position of paddle
public int getX(){
return x;
}
//Gets y position of paddle
public int getY(){
return y;
}
//sets width of paddle to parameter
public void setWidth(int i){
width = i;
}
//sets x position of paddle
public void setX(int i){
x = i;
}
//Sets y position of paddle
public void setY(int i){
y = i;
}
//Sets paddle's current PowerUp
public void setpUp(String s){
pUp = s;
}
}