-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerLife.js
44 lines (37 loc) · 930 Bytes
/
PlayerLife.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
class PlayerLife {
/**
* @type {GameScene}
*/
_scene = null;
/**
* @type {GameElement}
*/
_gameElement = null;
_points = 100;
_endCallback = () => {};
constructor(scene, endCallback) {
this._scene = scene;
this._endCallback = endCallback;
this.mount();
}
mount() {
const domElement = document.createElement("progress");
domElement.id = "life";
domElement.min = 0;
domElement.max = 100;
domElement.value = 100;
const lifeElement = new GameElement(domElement);
this._scene.renderGameElement(lifeElement);
this._gameElement = lifeElement;
}
get points() {
return this._points;
}
set points(value) {
this._points = value;
this._gameElement.setAttribute("value", value);
if (value <= 0) {
this._endCallback();
}
}
}