-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharcher.js
112 lines (97 loc) · 3.94 KB
/
archer.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
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
class Archer {
constructor(game, x, y, chats) {
Object.assign(this, { game, x, y, chats });
this.radius = 20;
this.visualRadius = 200;
this.spritesheet = ASSET_MANAGER.getAsset("./sprites/archer.png");
this.animations = [];
this.animations.push([]);
this.animations[0].push(new Animator(this.spritesheet, 4, 10, 48, 48, 5, 0.25, 26, false, true));
this.animations[0].push(new Animator(this.spritesheet, 64, 10, 48, 48, 5, 0.25, 26, false, true));
this.animations[0].push(new Animator(this.spritesheet, 128, 10, 48, 48, 5, 0.25, 26, false, true));
this.animations[0].push(new Animator(this.spritesheet, 183, 10, 48, 48, 5, 0.25, 26, false, true));
this.animations[0].push(new Animator(this.spritesheet, 239, 10, 48, 48, 5, 0.25, 26, false, true));
this.animations.push([]);
this.animations[1].push(new Animator(this.spritesheet, 4, 372, 48, 64, 2, 0.5, 10, false, true));
this.animations[1].push(new Animator(this.spritesheet, 64, 372, 48, 64, 2, 0.5, 10, false, true));
this.animations[1].push(new Animator(this.spritesheet, 128, 372, 48, 64, 2, 0.5, 10, false, true));
this.animations[1].push(new Animator(this.spritesheet, 183, 372, 48, 64, 2, 0.5, 10, false, true));
this.animations[1].push(new Animator(this.spritesheet, 239, 372, 48, 64, 2, 0.5, 10, false, true));
this.state = 0; // 0 walking, 1 attacking, 2 dead
this.facing = 5; // 0 = up, clockwise
this.elapsedTime = 0;
};
update() {
this.elapsedTime += this.game.clockTick;
if (this.game.click && collide(this, this.game.click)) {
if (distance(this, this.game.footy) < this.visualRadius) {
loadChat(this.chats[this.game.footy.state]);
} else {
loadChat(error[0]);
}
};
var dir = { x: (this.game.footy.x - this.x), y: (this.game.footy.y - this.y) };
this.facing = getFacing(dir);
};
draw(ctx) {
var xOffset = 25;
var yOffset = 30;
if (this.state === 0) {
switch (this.facing) {
case 0:
xOffset = 22;
yOffset = 30;
break;
case 1:
xOffset = 20;
yOffset = 28;
break;
case 2:
xOffset = 18;
yOffset = 28;
break;
case 3:
xOffset = 20;
yOffset = 25;
break;
case 4:
xOffset = 22;
yOffset = 25;
break;
case 5:
xOffset = 25;
yOffset = 25;
break;
case 6:
xOffset = 30;
yOffset = 25;
break;
case 7:
xOffset = 25;
yOffset = 25;
break;
}
}
if (this.facing < 5) {
this.animations[this.state][this.facing].drawFrame(this.game.clockTick, ctx, this.x - xOffset, this.y - yOffset, 1);
} else {
ctx.save();
ctx.scale(-1, 1);
this.animations[this.state][8 - this.facing].drawFrame(this.game.clockTick, ctx, -(this.x) - 48 + xOffset, this.y - yOffset, 1);
ctx.restore();
}
if (PARAMS.DEBUG) {
ctx.strokeStyle = "Red";
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
ctx.closePath();
ctx.stroke();
ctx.setLineDash([5, 15]);
ctx.beginPath();
ctx.arc(this.x, this.y, this.visualRadius, 0, 2 * Math.PI);
ctx.closePath();
ctx.stroke();
ctx.setLineDash([]);
}
};
};