Game Development Reference
In-Depth Information
p.destroy = function () {
var event;
this.enemySprite.on('animationend', function () {
event = new createjs.Event(events.ENEMY_DESTROYED, true);
this.dispatchEvent(event);
}, this);
this.enemySprite.gotoAndPlay(this.data.frame + '_die');
}
window.game.Enemy = Enemy;
}());
Creating the Enemy Health Bar
The health of the enemy is displayed as a progress bar, as well as text that shows the amount of hit points left. This
works very similarly to the progress bar component that you built in this topic, so the code should look pretty familiar.
The complete EnemyHealthBar class is shown in Listing 14-17.
Listing 14-17. EnemyHealthBar.js - The EnemyHealthBar Class Displays Enemy Hit Points
(function (window) {
window.game = window.game || {}
function EnemyHealthBar(maxHP) {
this.maxHP = this.HP = maxHP;
this.initialize();
}
var p = EnemyHealthBar.prototype = new createjs.Container();
p.Container_initialize = p.initialize;
p.progressBar = null;
p.maxHP = null;
p.HP = null;
p.hpTxt = null;
p.initialize = function () {
this.Container_initialize();
this.addHealthBar();
this.addHP();
}
p.addHealthBar = function () {
var barXOffset = 10;
var enemyBar = new createjs.Sprite(spritesheet, 'enemyBar');
var enemyBarBounds = enemyBar.getBounds();
var barBG = new createjs.Shape();
barBG.graphics.beginFill('#b6b6b6').drawRect(0, 0,
enemyBarBounds.width,
enemyBarBounds.height);
 
Search WWH ::




Custom Search