HTML and CSS Reference
In-Depth Information
var isoCoord = game.isoMaths.screenToIsoCoord
(localPt.x, localPt.y);
var isTileAvailable = (this.data[isoCoord.y] &&
this.data[isoCoord.y][isoCoord.x] === 'Tile');
if (game.isCreatingNewBuilding && isTileAvailable) {
var needCoins = game.BuildingsData
[game.buildingTypeToBePlaced].needCoins;
// deduce money
game.coins -= needCoins;
var event = new cjs.Event('placedBuilding');
event.buildingType = game.buildingTypeToBePlaced;
game.dispatchEvent(event); // trigger the event
game.isCreatingNewBuilding = false;
ghostBuilding.visible = false;
var newBuildingData = new game.Building
(isoCoord.x, isoCoord.y, event.buildingType);
game.buildingsList.push(newBuildingData);
// redraw the city tiles and buildings after changes.
this.redraw();
}
});
8. Now, we iniialize the interacion setup we just created inside the CityLayer
constructor funcion:
this.setupMouseInteraction();
9. We need to refine the redraw funcion to take the building data into the logic
of the code:
CityLayer.prototype.redraw = function() {
var newDataMap = game.helper.create2DArray
(this.rows, this.cols, 'Tile');
// construct the 2D map data with building list.
for (var i=0, len=game.buildingsList.length;
i<len; i++) {
var b = game.buildingsList[i];
var className = b.name;
newDataMap[b.y][b.x] = className;
}
 
Search WWH ::




Custom Search