HTML and CSS Reference
In-Depth Information
Engage thrusters
Let's complete this task with the following steps:
1. We have three more images to place in the city layer now. Define them in the
view-sprites.js
file using the following code:
// Buildings View
;(function(game, cjs){
(game.CoinsGenerator = function() {
game.Tile.call(this, 'images/coins-generator.png');
this.regX = 0;
this.regY = 94;
}).prototype = Object.create(game.Tile.prototype);
(game.Merchant = function() {
game.Tile.call(this, 'images/merchant.png');
this.regX = 0;
this.regY = 43;
}).prototype = Object.create(game.Tile.prototype);
(game.PowerSupply = function() {
game.Tile.call(this, 'images/power-supply.png');
this.regX = 0;
this.regY = 51;
}).prototype = Object.create(game.Tile.prototype);
}).call(this, game, createjs);
2. Let's move on to the
game.js
file. In the
CityLayer
constructor funcion, we add
the following code that iniializes the data of the map. We need
this
to compare
when drawing the buildings:
// 2D array that holds the type of building in string
this.data = game.helper.create2DArray
(this.rows, this.cols);
3. Next, we define a new code block for the
Building
deiniion. We also create an
empty array that will store the building instances:
;(function(game, cjs){
game.Building = function(isoX, isoY, viewClassName) {
this.name = viewClassName;
this.x = isoX;
this.y = isoY;
};
game.buildingsList = [];
}).call(this, game, createjs);