-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTurret.java
144 lines (98 loc) · 2.92 KB
/
Turret.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
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
package playerObjects;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.opengl.TextureLoader;
import grid.Grid;
public class Turret {
//A stands for location relative to array
private Vector2f locationA;
//This determines if the turret can hit flying units
protected boolean canHitFlying;
//This determines the damage of each attack by the turret
protected int atk;
//This determines the point at which the turret can attack
protected int range;
//This is the time in seconds it takes before a turret can fire again.
protected float atkSpd;
//This number gives the last time it was fired
private float firedLast;
//This shows if the unit hits multiple enemies or just one
protected boolean aoe;
protected int id;
protected int level;
protected int cost;
private int[] gridVal;
//This is the image that represents the turret for in game
Icon design;
//Sets the fields to the given values
public Turret(Vector2f l, boolean canFly, int a, int r, boolean aoe, Icon i, int atkSpd) {
locationA = l;
canHitFlying = canFly;
atk = a;
range = r;
this.aoe = aoe;
design = i;
firedLast = 0;
this.atkSpd=atkSpd;
id = 1;
cost = 20;
level = 1;
firedLast = atkSpd;
}
//This section returns fields
public Icon getDesign() {
return design;
}
public int getCost() {
return cost;
}
public Vector2f getLoc() {
return locationA;
}
public boolean isAoe() {
return aoe;
}
public int getRange() {
return range;
}
public int getAtk() {
return atk;
}
public int getId() {
return id;
}
public int getFiredLast() {
return (int) firedLast;
}
public void setFiredLast(int i) {
firedLast = i;
}
public int[] getGridVal() {
return gridVal;
}
public boolean canHitFlying() {
return canHitFlying;
}
//End of field return section
//draw the turret on the screen with input
public void draw(Graphics g, int x, int y){
g.drawImage(getDesign().getDesign(), x, y);
}
public void setGridVal(int[] i) {
gridVal = i;
}
public Bullet attack(Icon bullet, int milli, Enemy e, Grid gr) {
//TODO: Copy Enemy.java from computer at school
firedLast += milli;
Bullet b = new Bullet(bullet, atk, e, new Vector2f(gridVal[0]*gr.GRID_UNIT.x+gr.getLoc().x+15, gridVal[1]*gr.GRID_UNIT.y + gr.getLoc().y+15));
return b;
//This makes a bullet that targets an enemy trying to kill them by staying locked
//Bullets explode on collision normally regardless of target
// new Icon(new Image(TextureLoader.getTexture("jpg", new FileInputStream("./res/Bullet.png"))))
//TODO Make the bullet follow the target (Enemy e)
//Fired last ensures the atkSpd gates the turret's damage
}
public int getAtkSpd() {
return (int)atkSpd;
}
}