HTML and CSS Reference
In-Depth Information
var isoCoord = game.isoMaths.screenToIsoCoord
(localPt.x, localPt.y);
var isTileAvailable = ([isoCoord.y] &&[isoCoord.y][isoCoord.x] === 'Tile');
if (game.isCreatingNewBuilding && isTileAvailable) {
var needCoins = game.BuildingsData
// 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);
// redraw the city tiles and buildings after changes.
8. Now, we iniialize the interacion setup we just created inside the CityLayer
constructor funcion:
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 =;
newDataMap[b.y][b.x] = className;
Search WWH ::

Custom Search