HTML and CSS Reference
In-Depth Information
The first helper that we will add is exactly the same as create2DArray that we coded in the
previous project:
game.helper = game.helper || {};
game.helper.create2DArray = function(rows, cols, initialValue) {
var array = [];
for(var i=0; i<rows; i++) {
array[i] = [];
for (var j=0; j<cols; j++) {
array[i][j] = initialValue;
}
}
return array;
};
Engage thrusters
In the following steps, we will allow the player to place a building on the board grid:
1. First, let's create a base for the building deiniion in the building.js file
Every type of building is built on top of this logic:
var game = this.game || (this.game={});
var createjs = createjs || {};
var lib = lib || {};
// The base of Building definition.
;(function(game, cjs, lib){
function Building(){
cjs.Container.call(this);
}
Building.prototype = Object.create(cjs.Container.prototype);
Building.cost = 10; // energy cost
game.Building = Building;
}).call(this, game, createjs, lib);
2. Take the satellite.js file as an example. It extends the building base with its
own graphics and health points. Health point ( HP ) is useful when buildings take
damage from the enemy's atack. Also, each type of building has a diferent cost:
var game = this.game || (this.game={});
var createjs = createjs || {};
var lib = lib || {};
 
Search WWH ::




Custom Search