HTML and CSS Reference
In-Depth Information
this.currentStep = 1;
this.stepsSeconds = game.BuildingsData
[viewClassName].stepsSeconds;
this.buildTime = (new Date()).getTime();
};
2. Then, we deine the following ick method that helps the buildings grow. We may
put it next to the Building deiniion:
var cityGrowing = game.cityGrowing = {};
cityGrowing.tick = function() {
for (var i=0, len=game.buildingsList.length;
i < len; i++) {
var building = game.buildingsList[i];
// is consturction in the next stage?
var secondsDiff = Math.floor(((new Date()).getTime()
- building.buildTime) / 1000); // seconds
for (var j=0, length=building.stepsSeconds.length;
j < length; j++) { // loop the steps
if (secondsDiff >= building.stepsSeconds[j]) {
building.currentStep = j+2;
if (building.currentStep > length) {
building.isConstructionDone = true;
}
}
}
}
};
3. When we draw the iles and buildings in the city layer's redraw method, we draw
the construcion building graphics too:
// 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;
if (!b.isConstructionDone) {
className = "ConstructionStep" + b.currentStep;
}
newDataMap[b.y][b.x] = game.BuildingIDs[className];
}
 
Search WWH ::




Custom Search