-
Notifications
You must be signed in to change notification settings - Fork 1
/
Enemy_V2.java
153 lines (130 loc) · 3.1 KB
/
Enemy_V2.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
145
146
147
148
149
150
151
152
153
package data;
import static helpers.Artist.*;
import org.newdawn.slick.opengl.Texture;
public class Enemy {
private static final float TILE_SIZE = 64;
Texture alien = QuickLoad("Fire32");
private Texture texture, backHealth, frontHealth, healthOutline;
float x;
float y;
float width;
float hight;
Tile target;
Tile[] path;
public boolean isSpawned = false;
public boolean alive = true;
public int currPosition = 1;
public final float moveSpeed = 2f;
public Tile endPoint;
private int index;
private float health = 4, healthStart;
private boolean gotPoints = false;
public Enemy(Tile spawn, Tile endPoint, Tile[] path){
this.backHealth = QuickLoad ("backHealth");
this.frontHealth = QuickLoad ("frontHealth");
this.healthOutline = QuickLoad ("healthOutline");
this.x = spawn.getX();
this.y = spawn.getY();
this.width = spawn.getWidth();
this.hight = spawn.getHight();
this.path = path;
this.endPoint = endPoint;
this.index = 0;
this.healthStart = health;
DrawQuadTex(this.alien, x, y, width, hight);
}
public void move(){
if(this.x < this.path[currPosition].getX()){
this.x = this.x + moveSpeed;
if(this.y < this.path[currPosition].getY()){
this.y = this.y + moveSpeed;
}
else if(this.y > this.path[currPosition].getY()){
this.y = this.y - moveSpeed;
}
}
else if(this.x > this.path[currPosition].getX()){
this.x = this.x - moveSpeed;
if(this.y < this.path[currPosition].getY()){
this.y = this.y + moveSpeed;
}
else if(this.y > this.path[currPosition].getY()){
this.y = this.y - moveSpeed;
}
}
else{
if(this.y < this.path[currPosition].getY()){
this.y = this.y + moveSpeed;
}
else if(this.y > this.path[currPosition].getY()){
this.y = this.y - moveSpeed;
}else{
currPosition++;
}
}
}
public void DrawEnemy(){
float healthTotal = health / healthStart;
DrawQuadTex(this.alien, x, y, width, hight);
DrawQuadTex(backHealth, x, y - 14, width, 7);
DrawQuadTex(frontHealth, x, y - 14, TILE_SIZE * healthTotal, 7);
DrawQuadTex(healthOutline, x, y - 14, width, 7);
}
public Tile GetTarget(){
return this.target;
}
public void SetTarget(Tile target){
this.target = target;
}
public void setX(int x){
this.x = x;
}
public void setY(int y){
this.y = y;
}
public float getX(){
return this.x;
}
public float getY(){
return this.y;
}
public int getCurrPosition(){
return currPosition;
}
public boolean isAlive(){
return alive;
}
public void die(){
this.alive = false;
}
public float getWidth() {
return width;
}
public void setWidth(float width) {
this.width = width;
}
public float getHight() {
return hight;
}
public void setHight(float hight) {
this.hight = hight;
}
public void setHealth(int dmg){
this.health -= dmg;
}
public float getHealth(){
return this.health;
}
public void setIndex(int index){
this.index = index;
}
public int getIndex(){
return this.index;
}
public void gotPoints(){
this.gotPoints = true;
}
public boolean getGotPoints(){
return this.gotPoints;
}
}