This repository was archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuardTower.pde
66 lines (53 loc) · 1.52 KB
/
GuardTower.pde
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
class GuardTower extends Tower {
public static final int CAP = 3;
public static final int RESPAWN_COOLDOWN = 2000;
public static final int RALLYPOINT_RANGE = 50;
protected Group<Guard> guards;
protected PVector rallypoint;
protected float lastSpawn = HermesMath.MINUS_INFINITY;
public GuardTower(int type, Node node, Player player, Game game) {
super(Tower.MELEE, node, player, game);
_register();
this.guards = new Group(game);
this.rallypoint = _calcInitialRallypoint();
}
public Group<Guard> getGuards() {
return guards;
}
public PVector getRallypoint() {
return rallypoint;
}
public PVector getSpawnpoint() {
return getCenter();
}
public void update() {
if (guards.size() < CAP
&& _cooldownIsOver()) {
_spawnGuard();
}
}
public void addToGuards(Guard guard) {
player.addToGuards(guard);
guards.add(guard);
}
private void _spawnGuard() {
new Guard(UnitUtils.GRUNT, this, game);
lastSpawn = millis();
}
private PVector _calcInitialRallypoint() {
// store pairs of vertices that are adjacent path elements
// whose line contains at least one point
// for which dist(point, nodeCenter) < RALLYPOINT_RANGE
// set initial rallypoint to
return new PVector(300, 300);
}
private boolean _cooldownIsOver() {
return millis() - lastSpawn > RESPAWN_COOLDOWN;
}
protected void _register() {
super._register();
game.register(this);
player.addToTowers(this);
node.setTower(this);
}
}