-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerUps.java
More file actions
184 lines (168 loc) · 5.79 KB
/
PowerUps.java
File metadata and controls
184 lines (168 loc) · 5.79 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
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Arrays;
import java.awt.geom.*;
import java.lang.Math;
import java.awt.image.BufferedImage;
import javax.imageio.*;
import java.awt.geom.AffineTransform;
/**
* The code for many of the different powerups
*
* Useful Methods:
* fastBlockBreaking: increases user block-breaking
* speed
* teleport: moves user five blocks in the direction
* user is facing
* autoRespawn: instantly teleports user back to
* home base
* extraBlocks: user gets 200 blocks before
* needing to replenish
* toggleFlashlight: user can manually increase
* viewing size by specified blocks
* newSpawn: creates a new spawning location for base
* on the same side of the map
*
* @Avi and Amar Ruthen
* @12.22.2020
*/
public class PowerUps
{
BufferedImage compass = null;
int numSquaresAcross;
int squareSize;
boolean fastBreaking;
Grid grid;
Character user;
Base userBase;
Base compBase;
PowerUps p;
Block[] userBlocks = new Block[1000];
Block[] immovableBlocks = new Block[10];
Block[] neutralBlocks = new Block[500];
Block[] compBlocks = new Block[1000];
/**
* Constructor for the PowerUps class
* Transfers all objects and variables here for use
*/
public PowerUps(Base userBase, Base compBase, Character user, Grid grid,
Block[] userBlocks, Block[] immovableBlocks, Block[] neutralBlocks,
Block[] compBlocks, int w, int h, int numSquaresAcross)
{
this.userBase = userBase;
this.compBase = compBase;
this.user = user;
this.grid = grid;
this.userBlocks = userBlocks;
this.immovableBlocks = immovableBlocks;
this.neutralBlocks = neutralBlocks;
this.compBlocks = compBlocks;
this.numSquaresAcross = numSquaresAcross;
squareSize = 600 / numSquaresAcross;
}
/**
* Doubles the speed of breaking blocks
*
* @param blockBreakingSpeed takes the current block-breaking speed
* (is variable blockBreakingSpeed in Graphics Window)
*
* @return the new blockBreakingSpeed for the user
*/
public int fastBlockBreaking(int blockBreakingSpeed)
{
//allows you to toggle fastBreaking on and off
fastBreaking = !fastBreaking;
if (fastBreaking)
return blockBreakingSpeed/2; //breaks blocks faster
return blockBreakingSpeed*2; //breaks blocks slower
}
/**
* Moves user five blocks in the direction they are facing
*
* Will adjust teleportation distance if the last block the user
* will land on is a block
*
* @param g allows for graphical movement of user from the PowerUps class
*/
public void teleport(GraphicsWindow g)
{
int numBlocksAhead = user.teleportMove(compBlocks, neutralBlocks, immovableBlocks);
for (int i = 0; i < numBlocksAhead; i++)
{
if (user.canMove(compBlocks, neutralBlocks, immovableBlocks, true, -1))
g.move(user.faceDirection);
}
}
/**
* Automatically teleports user back to their home base from anywhere on map
*
* @param g allows for graphical movement of user from the PowerUps class
*/
public void autoRespawn(GraphicsWindow g)
{
//Calculates horizontal and vertical distance to the userBase
int deltaX = userBase.initialX - grid.toGridCoords(user.xLoc, true);
int deltaY = userBase.initialY - grid.toGridCoords(user.yLoc, false);
//Moves the user instantaneously to the correct xLocation on the map
if(deltaX >= 0)
{
for(int i = 0; i < deltaX; i++)
g.move(3);
}
else
{
for(int i = 0; i > deltaX; i--)
g.move(2);
}
//Moves the user instantaneously to the correct yLocation on the map
if(deltaY >= 0)
{
for(int i = 0; i < deltaY; i++)
g.move(1);
}
else
{
for(int i = 0; i > deltaY; i--)
g.move(0);
}
g.move(1); //Extra movement needed as center xLoc
g.move(3); //and yLoc for picture is one off
}
/**
* Gives user access to more blocks without replenishment
* by increasing blocksAllowed
*/
public void extraBlocks()
{
user.increaseBlocksAllowed(200);
}
/**
* Allows user to toggle the size of their viewing screen
* from a 10x10 to a 20x20
*
* NOTE: setFogSize sets the number of viewable blocks in
* one direction, then applies that for all directions
*/
public void toggleFlashlight()
{
if(grid.fogSize == 5)
grid.setFogSize(10); //Change the viewing size by given # of blocks
else
grid.setFogSize(5);
}
/**
* Sets a new spot for the userBase (on the same side of the map as before)
*/
public void newSpawn()
{
//Creates a temporary base that will create the new spawn location
Base t = new Base(0, 0, squareSize, true);
//Checks the side of the map the userBase currently is
t.userOnTop = userBase.userOnTop;
//Randomizes a new location given its side on the map
int userBaseX = t.setRandomX(grid);
int userBaseY = t.setRandomY(userBaseX, grid);
userBase.setInitialCoords(userBaseX, userBaseY);
}
}