-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoveanimator.js
74 lines (61 loc) · 1.6 KB
/
moveanimator.js
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
function MoveAnimator(aimove, game) {
this.aimove = aimove;
this.game = game;
this.path =
this.aimove === undefined
?
undefined
:
get_path
(
aimove.unit.move,
game,
aimove.unit.x,
aimove.unit.y,
aimove.x,
aimove.y,
get_path_find_walk_test_fn(game)
);
}
/*
* Applies the move.
* The unit stored in the move will be selected.
*/
MoveAnimator.prototype.go =
function() {
this.start_time = 0;
console.log("moving "+this.aimove.unit.name+" to "+this.aimove.x+","+this.aimove.y);
var t = this;
this.intervalid =
window.setInterval(
move_animator_frame, 500, t
);
}
function move_animator_frame(ma) {
var m = ma.aimove;
var g = ma.game;
var move_finished = false;
assert(m !== undefined);
g.selectUnit(m.unit.id);
if (m.doMove)
{
var pos = ma.path.pop();
if (pos !== undefined)
g.moveCurrentUnit(pos.x, pos.y);
else
move_finished = true;
}
else
{
console.log(m.unit.name+" decided not to move.");
move_finished = true;
}
if (move_finished && m.target) {
console.log(m.unit.name+" is attacking "+m.target.name);
g.attackWithCurrentUnit(m.target.id);
}
if (move_finished) {
window.clearInterval(ma.intervalid);
console.log('cleared');
}
}