49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
function HeartGauge(heartManager) {
|
|
this.heartManager = heartManager;
|
|
this.hearts = [];
|
|
|
|
var self = this;
|
|
this.heartManager.addOnChangeCountListener(
|
|
function() { self.onChangeCountListener(); }
|
|
);
|
|
|
|
this.heartManager.addOnChangeMaxCountListener(
|
|
function() { self.onChangeMaxCountListener(); }
|
|
);
|
|
|
|
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);
|
|
}
|
|
};
|
|
|
|
HeartGauge.prototype.onChangeCountListener = function() {
|
|
this.updateHearts();
|
|
}
|
|
|
|
HeartGauge.prototype.onChangeMaxCountListener = function() {
|
|
this.updateHearts();
|
|
}
|
|
|
|
HeartGauge.prototype.start = function() {
|
|
this.updateHearts();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
HeartGauge.GAP = 35;
|
|
HeartGauge.HEART_SCALE = 0.6; |