Game Development Reference
In-Depth Information
The update functions come next. The update function upgrades the obstacle properties to
increase game difficulty as the play progresses. It adds new obstacles based the
lastObstacleTime value. Finally, it loops through the lists of obstacles and exhaustParicles ,
updating their positions on the game screen.
private function update(timeDifference:Number = 0):void {
var timeBasedModifier:Number = (timeDifference / 1000)*timeBasedUpdateModifier;
//score
if (playerStarted && getTimer() > (lastScoreEvent + scoreDelay)) {
score += (10 + obstacleSpeed);
}
//obstacles additions
if (getTimer() > lastObstacleUpgrade +obstacleUpgradeWait) {
lastObstacleUpgrade = getTimer();
obstacleDelay -= obstacleDelayDecrease;
if (obstacleDelay < obstacleDelayMin) {
obstacleDelay = obstacleDelayMin;
}
trace("obstacleDelay=" + obstacleDelay);
obstacleHeightMax += obstacleHeightIncrease;
if (obstacleHeightMax > obstacleHeightLimit) {
obstacleHeightMax = obstacleHeightLimit;
}
trace("obstacleHeightMax=" + obstacleHeightMax);
obstacleSpeed++;
if (obstacleSpeed > obstacleSpeedMax) {
obstacleSpeed = obstacleSpeedMax;
}
trace("obstacleSpeed=" + obstacleSpeed);
obstacleColorIndex++;
if (obstacleColorIndex == obstacleColors.length) {
obstacleColorIndex = obstacleColors.length - 1;
}
trace("obstacleColorIndex=" + obstacleColorIndex);
exhaustDelay= 100+((obstacleSpeedMax * 10) - (10 * obstacleSpeed));
}
// add new obstacles
var obstaclePoolCount:int = obstaclePool.length -1;
if (getTimer() > (lastObstacleTime + obstacleDelay) && obstaclePoolCount>0) {
//trace("creating an obstacle");
lastObstacleTime = getTimer();
tempObstacle = obstaclePool.pop();
tempObstacle.bitmapData.setPixel(0, 0, obstacleColors[obstacleColorIndex]);
//is it going to be in the center?
if (int(Math.random() * 100) < centerFrequency) {
tempObstacle.y = 120 + Math.random()*200;
tempObstacle.scaleY = centerHeight;
tempObstacle.scaleX = centerWidth;
}else {
tempObstacle.scaleY = randomNumberFromRange(obstacleHeightMin, obstacleHeightMax);
tempObstacle.scaleX = 5;
Search WWH ::




Custom Search