Fix: restructing session manager, ES6 -> ES5
This commit is contained in:
+36
-39
@@ -1,50 +1,47 @@
|
||||
class HeartGauge {
|
||||
function HeartGauge(heartManager) {
|
||||
this.heartManager = heartManager;
|
||||
this.hearts = [];
|
||||
|
||||
constructor(heartManager) {
|
||||
this.heartManager = heartManager;
|
||||
this.hearts = [];
|
||||
var self = this;
|
||||
this.heartManager.addOnChangeCountListener(
|
||||
function() { self.onChangeCountListener(); }
|
||||
);
|
||||
|
||||
let self = this;
|
||||
this.heartManager.addOnChangeCountListener(
|
||||
function() { self.onChangeCountListener(); }
|
||||
);
|
||||
this.heartManager.addOnChangeMaxCountListener(
|
||||
function() { self.onChangeMaxCountListener(); }
|
||||
);
|
||||
|
||||
this.heartManager.addOnChangeMaxCountListener(
|
||||
function() { self.onChangeMaxCountListener(); }
|
||||
);
|
||||
|
||||
let startPosX = GAME_SCREEN_SIZE.x - HeartGauge.GAP * 4;
|
||||
let posY = 30;
|
||||
for(let i = 0; i < HeartManager.HEART_MAX_COUNT; i++) {
|
||||
let heart = game.add.sprite(startPosX - i * HeartGauge.GAP, posY, "heart_full");
|
||||
heart.anchor.set(0.5);
|
||||
heart.scale.set(HeartGauge.HEART_SCALE);
|
||||
heart.alpha = 0;
|
||||
this.hearts.push(heart);
|
||||
}
|
||||
};
|
||||
|
||||
onChangeCountListener() {
|
||||
this.updateHearts();
|
||||
var startPosX = GAME_SCREEN_SIZE.x - HeartGauge.GAP * 4;
|
||||
var posY = 30;
|
||||
for(var i = 0; i < HeartManager.HEART_MAX_COUNT; i++) {
|
||||
var heart = game.add.sprite(startPosX - i * HeartGauge.GAP, posY, "heart_full");
|
||||
heart.anchor.set(0.5);
|
||||
heart.scale.set(HeartGauge.HEART_SCALE);
|
||||
heart.alpha = 0;
|
||||
this.hearts.push(heart);
|
||||
}
|
||||
};
|
||||
|
||||
onChangeMaxCountListener() {
|
||||
this.updateHearts();
|
||||
}
|
||||
HeartGauge.prototype.onChangeCountListener = function() {
|
||||
this.updateHearts();
|
||||
}
|
||||
|
||||
start() {
|
||||
this.updateHearts();
|
||||
}
|
||||
HeartGauge.prototype.onChangeMaxCountListener = function() {
|
||||
this.updateHearts();
|
||||
}
|
||||
|
||||
updateHearts() {
|
||||
for(let i = 0; i < this.heartManager.getMaxCount(); i++) {
|
||||
if(i < this.heartManager.getCount())
|
||||
this.hearts[i].loadTexture("heart_full");
|
||||
else
|
||||
this.hearts[i].loadTexture("heart_empty");
|
||||
HeartGauge.prototype.start = function() {
|
||||
this.updateHearts();
|
||||
}
|
||||
|
||||
this.hearts[i].alpha = 1;
|
||||
}
|
||||
HeartGauge.prototype.updateHearts = function() {
|
||||
for(var i = 0; i < this.heartManager.getMaxCount(); i++) {
|
||||
if(i < this.heartManager.getCount())
|
||||
this.hearts[i].loadTexture("heart_full");
|
||||
else
|
||||
this.hearts[i].loadTexture("heart_empty");
|
||||
|
||||
this.hearts[i].alpha = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user