-
Notifications
You must be signed in to change notification settings - Fork 0
/
slowing missile upgrade
82 lines (71 loc) · 2.4 KB
/
slowing missile upgrade
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
// Import Graphics and ArrayList
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.ArrayList;
/**
* New methods for subclass SlowBullet which inherits data and methods from Bullet
* @author Elliott, Sina, Christian
* @version June 6, 2014
*/
public class SlowBullet extends Bullet
{
private boolean freeze;
/**
* Constructs SlowBullet
* @param x the x coordinate of the slow bullet
* @param y the y coordinate of the slow bullet
* @param alien the alien the slow bullet is aimed at
* @param fast whether or not the slow bullet is in fast forward or not
* @param tower the tower that fired the slow bullet
* @param freeze whether or not the slow bullet is a freezing bullet or not
*/
public SlowBullet(double x, double y, Alien alien, Tower tower, boolean freeze)
{
super (x,y,10,15,0,alien, tower);
this.freeze=freeze;
}
/**
* Overrides the collision code for the Bullet (checking for collision with aliens and boundaries) so it slows the alien instead but does everything else the same
*/
public void collisionCheck(ArrayList<Alien> aliens)
{
// Checks if it is colliding with any aliens and if it is then it uses the slow method on the alien, changes to not intact and increases number of hits
for (Alien nextAlien : aliens)
{
if ((this.xPos - nextAlien.xPos()) * (this.xPos - nextAlien.xPos())
+ (this.yPos - nextAlien.yPos())
* (this.yPos - nextAlien.yPos()) <= (this.size/2.0+27/Math.sqrt(2)+this.speed/2)*(this.size/2.0+27/Math.sqrt(2)+this.speed/2)
&& nextAlien.isAlive()&&nextAlien.onScreen())
{
nextAlien.slow(freeze);
tower.increaseNoOfHits();
this.intact = false;
}
}
// Checks if it is out of bounds and then changes to not intact
if (this.xPos < 0 || this.yPos < 0||this.xPos>729||this.yPos>675)
{
this.intact = false;
}
}
/**
* Overrides the draw method to draw a different color bullet
*/
public void draw(Graphics g)
{
// Graphics for better drawing of sharp edges
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// If it is a slow bullet, it is yellow
if (!freeze)
g2.setColor(Color.YELLOW);
// Otherwise it is white
else
g2.setColor(Color.WHITE);
g2.fillOval((int) (xPos - size / 2), (int) (yPos - size / 2),
(int) size, (int) size);
}
}