-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.java
More file actions
200 lines (163 loc) · 4.41 KB
/
Enemy.java
File metadata and controls
200 lines (163 loc) · 4.41 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package playerObjects;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Sound;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Vector2f;
public class Enemy {
protected boolean canFly; //Can it fly?!!?!?!?
private int hp; //Health of enemy
protected int atk; //How much enemy damages base
protected int def; //Defense of enemy
protected Vector2f loc; //Location of enemy
protected Vector2f vel; //Speed of enemy
protected Vector2f size; //Size of enemy
protected Icon img; //Image for said enemy
private boolean alive;
private int reward;
private boolean killed;
private boolean damaged;
//makes an enemy with the traits specified
public Enemy(boolean canFly, int hp, int atk, int def, Vector2f loc, Vector2f vel, Vector2f size, Icon img) {
this.canFly = canFly;
this.setHp(hp);
this.atk = atk;
this.def = def;
this.loc = loc;
this.vel = vel;
this.size = size;
this.img = img;
reward = 4;
alive = true;
killed = false;
damaged = true;
}
public boolean getKilled() {
return killed;
}
public void setKilled(boolean b) {
killed = b;
}
public boolean getDamaged() {
return damaged;
}
public void setDamaged(boolean b) {
damaged = b;
}
//Creates grid at location
public void render(Graphics g)
{
if(getHp() > 0)
{
g.drawImage(img.getDesign(),loc.x, loc.y);
}
else
{
alive = false;
}
}
public int move(Vector2f goal, int milli) {
Vector2f unit = new Vector2f(0,0);
if(loc.x != goal.x) {
if(loc.x>goal.x) {
unit.x = -1;
} else {
unit.x = 1;
}
}
if(loc.y != goal.y) {
if(loc.y > goal.y) {
unit.y = -1;
} else {
unit.y = 1;
}
}
if(loc.y < goal.y+10 && loc.y > goal.y-10 && loc.x > goal.x-10 && loc.x < goal.x + 10) {
alive = false;
hp = 0;
return atk;
}
loc = loc.add(new Vector2f(vel.x*unit.x, vel.y*unit.y).scale((float)milli/1000));
return 0;
}
public int getReward() {
return reward;
}
public boolean isAlive() {
return alive;
}
public void hit()
{
setHp(getHp() - 1);
}
public boolean canFly()
{
return canFly;
}
public void setLoc(Vector2f l) {
loc = l;
}
public Vector2f getLoc() {
return loc;
}
public int hp()
{
return getHp();
}
public int atk()
{
return atk;
}
public int def()
{
return def;
}
public Vector2f findLocation()
{
return loc;
}
public Icon img()
{
return img;
}
public Vector2f getDirection(Vector2f one, Vector2f two)
{
int a = ((int)one.getX());
int b = ((int)one.getY());
int c = ((int)two.getX());
int d = ((int)two.getY());
//I made this into unit vectors, so you multiply their value by the size of 1 grid box
Vector2f left = new Vector2f((-1), 0);
Vector2f right = new Vector2f((1), 0);
Vector2f up = new Vector2f(0, (-1));
Vector2f down = new Vector2f(0, 1);
if(a > c)
{
return left;
}
else if (c > a)
{
return right;
}
else if (b > d)
{
return down;
}
else
{
return up;
}
}
public int getHp() {
return hp;
}
public void setHp(int hp) {
this.hp = hp;
}
}