-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArtillery.java
More file actions
70 lines (65 loc) · 1.93 KB
/
Artillery.java
File metadata and controls
70 lines (65 loc) · 1.93 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
import greenfoot.*;
import java.util.List;
/**
* The Artillery weapon available as the second upgrade of tower. <br>
*
* @author (Terence Lai)
*/
public class Artillery extends Weapon
{
String name;
public Artillery(int speed, int power,int aoe, int eleId, Enemy target, String element)
{
super( speed, power, aoe, eleId, target, element ,"Shell"); //calls the super classes constructtor, nothign changed
}
public void act()
{
if (active) // move the weapon when active, called from the superclass
{
move();
checkHit(aoe);
}
else
{
m.removeObject(this);
}
}
protected void move(){
if (target!= null && m.checkEnemy(target) == true)
{
//System.out.println(target);
turnTowards(target.getX(), target.getY());
move(speed) ;
}//IllegalActor here making it turn when its not there (DID JAMES ADDD THIS?)
else
{
active = false;
}
}
/**
* checks to see what the rocket hit, and removes it, aoe is splash damage.
*/
private void checkHit(int aoe)
{
// Enemy e = (Enemy) getOneIntersectingObject(Enemy.class);
List<Enemy> hit = getObjectsInRange(10,Enemy.class);
if ( hit.size() != 0 && hit.get(0) == target)
{
List<Enemy> temp = getObjectsInRange(aoe/2,Enemy.class);
for (int i = 0; i < temp.size();i++)
{
Enemy x = temp.get(i);
if (x!= null)
{
x.damage(power, elementId);
}
}
m.addObject (new Explosion (aoe), this.getX(), this.getY());
active = false ; //removes the object in the world
}
if(m.withinField(this.getX(), this.getY()) == false )
{
active = false;
}
}
}