-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerUp.java
More file actions
198 lines (172 loc) · 3.72 KB
/
PowerUp.java
File metadata and controls
198 lines (172 loc) · 3.72 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* This Class handles all the power up attributes,
* if you get a power up this class will apply and remove the effect
* @author elan
*
*/
public class PowerUp
{
/**
* Some static variables to store the state of the game befor the power up took effect,
* thus it will be able to be reverted later,
* all private and static
*/
private static int fireRate;
private static int playerDamage;
private static int enemyDamage;
private static int numberBulletsPlayerShoots;
private static double enemySpeed;
private static double enemyBulletSpeed;
private static boolean shieldActive = false;
private static String text;
/**
* Constructor for PowerUp
* fetches current state values and stores it in the Class
*/
public PowerUp()
{
fireRate = States.fireRate;
playerDamage = States.playerDamage;
enemyDamage = States.enemyDamage;
numberBulletsPlayerShoots = States.numberBulletsPlayerShoots;
enemySpeed = States.enemySpeed;
enemyBulletSpeed = States.enemyBulletSpeed;
activate();
}
/**
* randomly (weighted) selects a powerUp and activates it
*/
public void activate()
{
int randomChance = (int)(Math.random()*100);
if(randomChance <= 19)
{
instaKill();
}
else if(randomChance <= 29)
{
slowMo();
}
else if(randomChance <= 39)
{
machineGun();
}
else if(randomChance <= 44)
{
rapidFire();
}
else if(randomChance <= 54)
{
shield();
}
else if(randomChance <= 64)
{
multiShot();
}
else if(randomChance <= 69)
{
bulletPulse();
}
else if(randomChance <= 89)
{
heal();
}
else
{
addLife();
}
if(GameTimer.powerUpTimer.isRunning())
GameTimer.powerUpTimer.restart();
else
GameTimer.powerUpTimer.start();
Controller.soundManager.playPowerUp();
}
/**
* Activates slow Motion Powerup
*/
public void slowMo()
{
States.enemyBulletSpeed *= 0.3;
States.enemySpeed *= 0.3;
text = "SLOW MOOOOO....";
}
public void instaKill()
{
States.playerDamage = Integer.MAX_VALUE;
text = "INSTA-KILL!";
}
public void machineGun()
{
States.fireRate *= 0.25;
GameTimer.updateShootTimer();
text = "Fire Rate Up";
}
public void rapidFire()
{
States.fireRate = 0;
GameTimer.updateShootTimer();
text = "Fire Rate WAAAY Up!";
}
public void shield()
{
States.enemyDamage = 0;
shieldActive = true;
text = "Bullet Shield";
}
public void multiShot()
{
States.numberBulletsPlayerShoots += (int)(Math.random()*5 + 1);
text = "Multi-Shot";
}
public void bulletPulse()
{
States.numberBulletsPlayerShoots = 72;
text = "No one lives....";
}
public void heal()
{
Controller.player.setHP(States.playerHP);
text = "HEALED!";
}
public void addLife()
{
States.playerLives[0]++;
text = "ADD LIFE!";
}
/**
* removes the effects of the powerUp
*/
public void deActivate()
{
States.fireRate = fireRate;
States.playerDamage = playerDamage;
States.enemyDamage = enemyDamage;
States.numberBulletsPlayerShoots = numberBulletsPlayerShoots;
States.enemySpeed = enemySpeed;
States.enemyBulletSpeed = enemyBulletSpeed;
shieldActive = false;
GameTimer.updateShootTimer();
}
/**
* Deactivates the power Ups
*/
public static void clearPowerUps()
{
if(Controller.powerUp != null)
{
Controller.powerUp.deActivate();
Controller.powerUp = null;
}
GameTimer.powerUpTimer.stop();
}
/**
* Draws the power up details on the screen
*/
public void render()
{
if(shieldActive)
StdDraw.picture(Controller.player.getX(), Controller.player.getY(), "shield.png", States.SHOOTER_SIZE, States.SHOOTER_SIZE);
StdDraw.setPenColor(StdDraw.BOOK_BLUE);
StdDraw.text(States.WINDOW_RESOLUTION - text.length()*StdDraw.getFont().getSize()*0.4, States.SHOOTER_SIZE/(double)4, text);
}
}