HTML and CSS Reference
In-Depth Information
function evaluatePowerSupply(value) {
game.powerSupplies += value;
}
function evaluateCoinsGeneration() {
// each coin generator speed up the count down by 3 units.
game.coinGenerationCountdown -= 3;
}
function evaluateMerchant(building) {
var b = building
if (!b.diamondTick) {
b.diamondTick = 0;
}
b.diamondTick += 1;
if (b.diamondTick >= game.setting.tickCountForMerchantDiamond) {
// trade coins to diamonds
if (game.coins >= game.setting.coinsNeedForDiamond) {
game.coins -= game.setting.coinsNeedForDiamond;
game.uiLayer.popDiamond(b);
b.diamondTick = 0;
}
}
}
6. We have the following ick funcion to really count the generaion of coins and
invoke our methods:
game.tick = function() {
game.coinGenerationCount += 1;
if (game.coinGenerationCount >=
game.coinGenerationCountdown) {
game.coins += 1;
game.coinGenerationCount = 0;
}
game.calculateBuildingsEffects();
};
7. Finally, we add the ick funcion to Ticker in order to execute it on every frame:
cjs.Ticker.addEventListener('tick', game.tick);
 
Search WWH ::




Custom Search