-
Notifications
You must be signed in to change notification settings - Fork 1
/
HealthBar.js
39 lines (32 loc) · 919 Bytes
/
HealthBar.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
class Heart extends PIXI.Sprite {
constructor(n) {
super(resources["images/heart.png"].texture);
this.initialProportion = this.width/this.height;
this.width = 60;
this.height = this.width*this.initialProportion;
this.y = 20;
this.x = app.renderer.width - (this.width+5)*(n+1);
app.stage.addChild(this);
}
}
class HealthBar {
constructor() {
this.value = 3;
this.hearts = [0,1,2].map(x => new Heart(x));
this.hitStop = false;
}
minus() {
if (this.hitStop) {return;}
this.value -= 1;
if (this.value === 0) {
game.on = false;
}
else if (this.value < 0) {
return;
}
this.hearts[this.hearts.length-1].alpha = 0;
this.hearts.pop();
this.hitStop = true;
window.setTimeout(() => {this.hitStop=false;}, 1000);
}
}