HTML and CSS Reference
In-Depth Information
for (var i=this.enemyList.length-1; i>=0; i--) {
// loop all bullets
for (var j=this.bulletList.length-1; j>=0; j--) {
var bullet = this.bulletList[j];
var pos = bullet.localToLocal(0, 0, this);
var rowCol = this.screenToRowCol(pos.x, pos.y);
if (this.enemyMap[rowCol.col][rowCol.row] !== undefined) {
var enemy = this.enemyMap[rowCol.col][rowCol.row];
// damage enemy
enemy.damage(bullet.damageDeal);
if (enemy.hp <= 0) {
this.enemyMap[enemy.col][enemy.row] = undefined;
game.helper.removeItem(this.enemyList, enemy);
enemy.parent.removeChild(enemy);
}
// remove bullet
game.helper.removeItem(this.bulletList, bullet);
bullet.parent.removeChild(bullet);
}
}
}
The following screenshot shows a bullet that was fired from a castle towards an enemy
unit on the board. A few seconds after this screen, the bullet will meet the enemy and
deal damage to the enemy. Then, the bullet is removed from the game.
 
Search WWH ::




Custom Search