-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoffin.js
63 lines (53 loc) · 1.76 KB
/
coffin.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
Coffin = function (type, id, x, y, width, height, img) {
var self = Entity(type, id, x, y, width, height, img);
self.coffinframeCount = 0;
self.isAwaken = false;
self.draw = function () {
ctx.save();
var x = self.x - player.x;
var y = self.y - player.y;
x += WIDTH / 2;
y += HEIGHT / 2;
var frameWidth = self.img.width / 6;
ctx.drawImage(self.img, 0, 0, frameWidth, frameWidth, x - (TILE_SIZE), y - (TILE_SIZE) + 2, self.width + 2, self.height + 2)
ctx.restore();
}
self.update = function () {
if (self.coffinframeCount < 126 && self.isTriggered) {
self.coffinframeCount += 4;
} else if (self.coffinframeCount >= 126) {
self.coffinframeCount = 125
if (!self.isAwaken) {
targetGenerateEnemy(self.x + TILE_SIZE / 2, self.y - TILE_SIZE / 2);
self.isAwaken = true;
}
}
if (self.testCollision({ x: player.x, y: (player.y + (player.height / 2)), width: player.width, height: 1 }) && !self.isTriggered) {
self.isTriggered = true;
self.draw = function () {
ctx.save();
var x = self.x - player.x;
var y = self.y - player.y;
x += WIDTH / 2;
y += HEIGHT / 2;
var frameWidth = self.img.width / 6;
var walk = Math.floor(self.coffinframeCount / 25)
ctx.drawImage(self.img, walk * frameWidth, 0, frameWidth, frameWidth, x - (TILE_SIZE), y - (TILE_SIZE) + 2, self.width + 2, self.height + 2)
ctx.restore();
}
}
self.draw();
}
coffinList[id] = self;
}
generateCoffin = function (colX, rowY) {
var x = colX * TILE_SIZE + TILE_SIZE
var y = rowY * TILE_SIZE + TILE_SIZE
var height = ((TILE_SIZE * 2) - 2);
var width = ((TILE_SIZE * 2) - 2);
var id = Math.random()
Img.coffin = new Image();
Img.coffin.src = "./img/Vampire-Coffin.png"
img = Img.coffin;
Coffin("coffin", id, x, y, width, height, img)
}