HTML and CSS Reference
In-Depth Information
// properties that need to be overridden
this.hp = 100;
this.shield = 0;
this.damageDeal = 0;
this.attackSpeed = 9999; // smaller means faster
}
Building.prototype = Object.create(cjs.Container.prototype);
Building.prototype.damage = function(damage) {
var realDamage = Math.max(damage - this.shield, 0); // min 0.
this.hp -= realDamage;
if (this.hp <= 0 && this.parent) { // a building may have been
destroyed by more than one enemies and result in no parent.
this.parent.removeBuilding(this);
}
};
Building.cost = 10; // consume energies
game.Building = Building;
}).call(this, game, createjs, lib);
2. Once the enemy atacks a building, we should be able to remove the building from
the board:
Board.prototype.removeBuilding = function(building) {
this.buildingMap[building.col][building.row] = undefined;
this.removeChild(building);
};
3. Inside the tick funcion, we add logic for the duraion in which the enemy is in
contact with the buildings:
// check enemy contacts buildings
for (var i=this.enemyList.length-1; i>=0; i--) {
var enemy = this.enemyList[i];
var row = enemy.row;
var col = enemy.col;
//contact building
var target = undefined;
if (this.buildingMap[col][row] !== undefined) { // current tile
target = this.buildingMap[col][row];
}else if (this.buildingMap[col][row+1] !== undefined) { // next
tile
target = this.buildingMap[col][row+1];
}
// has target
 
Search WWH ::




Custom Search