HTML and CSS Reference
In-Depth Information
// tick waves
game.waves.tick();
// the wave is cleared when:
// waves not generating new enemies and all existing enemies are
killed.
if (!game.waves.isActive &&
game.boardLayer.areEnemiesCleared()) {
game.boardLayer.isAddingBuilding = false;
game.boardLayer.removeAllBuildings();
game.boardLayer.removeAllBullets();
game.waves.waveCleared();
// 'Wave Cleared' graphics animation.
cjs.Tween.get(game.nextWaveSprite)
.to({x: game.canvas.width/2, y: game.canvas.height/2, alpha:
0}, 0)
.to({alpha: 1.0}, 300)
.wait(1000)
.to({alpha: 0}, 300)
.to({x: 999});
}
};
8. Next, we need some clearing and reseing logic. In the board.js file, we add a
method to remove all the buildings:
Board.prototype.removeAllBuildings = function(){
for (var i=0; i<this.cols; i++) {
for(var j=0; j<this.rows; j++) {
if (this.buildingMap[i][j]) {
this.removeBuilding(this.buildingMap[i][j]);
}
}
}
};
9. We need to know whether all the enemies are removed to know whether the wave
is cleared. We define the following method in the Board object:
// Have all existing enemies been killed?
Board.prototype.areEnemiesCleared = function(){
return (this.enemyList.length === 0);
};
 
Search WWH ::




Custom Search