-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.java
91 lines (78 loc) · 2.98 KB
/
Enemy.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
package com.g64.model.entities.enemy;
import com.g64.controller.GameController;
import com.g64.controller.commands.Command;
import com.g64.controller.commands.Null;
import com.g64.model.MapModel;
import com.g64.model.Position;
import com.g64.model.entities.EntityModel;
import com.g64.model.entities.enemy.humours.AggroedHumour;
import com.g64.model.entities.enemy.humours.EnemyHumour;
import com.g64.model.entities.enemy.humours.NormalHumour;
import com.g64.model.items.drops.Drop;
import com.googlecode.lanterna.TextColor;
public abstract class Enemy extends EntityModel {
AggroedHumour aggroedHumour;
NormalHumour normalHumour;
EnemyHumour activeHumour;
int movementCooldown;
int attackValue;
int visionDistance;
public Enemy(Position position, String string, TextColor color, boolean collision, Drop[] drops, int maxHealth, int attackValue, int visionDistance) {
super(position, string, color, collision, drops, maxHealth);
this.movementCooldown = 0;
this.attackValue = attackValue;
this.visionDistance = visionDistance;
}
public void updateState(Position playerPosition) {
if (this.position.distanceTo(playerPosition) <= visionDistance) setAggroedState();
else setNormalState();
}
public int getAttackValue() {
return attackValue;
}
@Override
public Command update(GameController controller) {
if (movementCooldown == 0) {
this.movementCooldown = activeHumour.getMaxCooldown();
return activeHumour.enemyAction(controller);
}
else {
updateState(controller.getPlayer().getPosition());
movementCooldown--;
return new Null();
}
}
public void setAggroedState(){
this.setColor(aggroedHumour.getColor());
activeHumour = aggroedHumour;
}
public void setNormalState(){
this.setColor(normalHumour.getColor());
activeHumour = normalHumour;
}
public EnemyHumour getActiveHumour(){ return activeHumour; }
public AggroedHumour getAggroedHumour() { return aggroedHumour; }
public NormalHumour getNormalHumour() { return normalHumour; }
public void setMovementCooldown(int movementCooldown) {
this.movementCooldown = movementCooldown;
}
@Override
public void handleBoundaryCrossing(MapModel map){
MapModel.Crossing crossing = map.checkBoundaries(position);
switch (crossing){
case NO_CROSS: break;
case CROSS_DOWN:
setPosition(new Position(position.getX(), map.thisChunk().getHeight() - 1));
break;
case CROSS_UP:
setPosition(new Position(position.getX(), 0));
break;
case CROSS_LEFT:
setPosition(new Position(0, position.getY()));
break;
case CROSS_RIGHT:
setPosition(new Position(map.thisChunk().getWidth() - 1, position.getY()));
break;
}
}
}