-
Notifications
You must be signed in to change notification settings - Fork 0
/
explosion.js
31 lines (31 loc) · 1.02 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
export default class Explosion {
constructor(game, enemy){
this.game = game;
this.enemy = enemy;
this.width = 192;
this.height = 192;
this.x = enemy.x - enemy.width * 0.5;
this.y = enemy.y - enemy.height * 0.4;
this.image = document.getElementById('explosion');
this.frameX = 0;
this.maxFrame = 4;
this.toDelete = false;
this.fps = Math.random() * 10 + 5;
this.frameInterval = 1000/this.fps;
this.frameTimer = 0;
this.sound = new Audio('./sounds/explosion.mp3');
}
update(deltaTime){
this.sound.play();
if (this.frameTimer > this.frameInterval){
this.frameX++;
this.frameTimer = 0;
} else {
this.frameTimer += deltaTime;
}
if (this.frameX > this.maxFrame) this.toDelete = true;
}
draw(context){
context.drawImage(this.image, this.frameX * this.width, 0, this.width, this.height, this.x, this.y, this.width, this.height);
}
}