-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplosion.js
91 lines (88 loc) · 2.75 KB
/
explosion.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
class Explosion {
constructor() {
this.spriteWidth = 64;
this.spriteHeight = 64;
this.frameX = 1;
this.timeToNewFrame = 0;
this.frameInterval = 100;
this.markedForDeletion = false;
}
draw(context) {
context.drawImage(this.image, this.x, this.y, this.width, this.height);
}
}
export class DustCloud extends Explosion {
constructor(x, width, game) {
super(width);
this.game = game;
this.x = x + width / 3;
this.y = this.game.height - 300;
this.maxFrames = 11;
this.width = this.spriteWidth * 5;
this.height = this.spriteHeight * 5;
this.image = document.getElementById(`dust${this.frameX}`);
}
update(deltaTime) {
this.x -= this.game.speed;
if (this.timeToNewFrame >= this.frameInterval) {
this.frameX++;
if (this.frameX >= this.maxFrames) {
this.markedForDeletion = true;
}
this.image = document.getElementById(`dust${this.frameX}`);
this.timeToNewFrame = 0;
} else {
this.timeToNewFrame += deltaTime;
}
}
}
export class BlueExplosion extends Explosion {
constructor(x, y, width, game) {
super(y, width);
this.game = game;
this.x = x + width / 2;
this.y = y;
this.maxFrames = 12;
this.width = this.spriteWidth * 5;
this.height = this.spriteHeight * 5;
this.image = document.getElementById(`blue${this.frameX}`);
}
update(deltaTime) {
this.x -= this.game.speed;
if (this.timeToNewFrame >= this.frameInterval) {
this.frameX++;
if (this.frameX >= this.maxFrames) {
this.markedForDeletion = true;
}
this.image = document.getElementById(`blue${this.frameX}`);
this.timeToNewFrame = 0;
} else {
this.timeToNewFrame += deltaTime;
}
}
}
export class RedExplosion extends Explosion {
constructor(x, y, width, game) {
super(width);
this.game = game;
this.x = x - 100;
this.y = y - 100;
this.maxFrames = 10;
this.width = this.spriteWidth * 3;
this.height = this.spriteHeight * 3;
this.image = document.getElementById(`red${this.frameX}`);
}
update(deltaTime) {
this.x -= this.game.speed;
if (this.timeToNewFrame >= this.frameInterval) {
this.frameX++;
if (this.frameX >= this.maxFrames) {
this.markedForDeletion = true;
}
this.image = document.getElementById(`red${this.frameX}`);
this.timeToNewFrame = 0;
} else {
this.timeToNewFrame += deltaTime;
}
}
}