Game Development Reference
In-Depth Information
canvasBitmapData.copyPixels(backgroundBitmapData,
tempExhaustParticle.bitmapData.rect,
blitPoint);
if (tempExhaustParticle.update(timeBasedModifier)) {
//return true if particle is to be removed
tempExhaustParticle.frame = 0;
exhaustPool.push(tempExhaustParticle);
exhaustParticles.splice(ctr,1);
}
}
canvasBitmapData.unlock();
You will notice that this blit is very similar to the blits in previous chapters. We simply need
blitPoint to be the current location (x and y) of the particle. It is then erased by copying that
background Rectangle from the same starting location to the canvasBitmapData . This effectively
erases only the portion of the canvasBitmapData that needs to be updated and not the entire
canvasBitmapData .
Increasing the game difficulty
As the game plays, we will increase its difficulty every 10 seconds ( obstacleUpgradeWait value).
Specifically, we will change the color, frequency, and speed of the obstacles. The
lastObstacleUpgrade variable will hold the return value of a getTimer function call from the last
difficulty increase.
private var obstacleUpgradeWait:int = 10000;
private var lastObstacleUpgrade:int;
Obstacles will be pulled from the pool and placed to start at the right-hand side of the play field
based on the obstacleDelay value. This is the number of milliseconds to wait between obstacles.
Every 10 seconds, along with the rest of the obstacle upgrades, this obstacleDelay will decrease
by obstacleDelayDecrease until it reaches obstacleDelayMin .
private var lastObstacleTime:int;
private var obstacleDelay:int = 800;
private var obstacleDelayMin:int = 50;
private var obstacleDelayDecrease:int = 150;
When an obstacle is to be created, it will either be a top, bottom, or center obstacle. The
centerFrequency value is the percentage chance that a center obstacle will be created. The
centerWidth and centerHeight control the dimensions of all center obstacles.
private var centerFrequency:int = 15;
private var centerHeight:int = 10;
private var centerWidth:int = 15;
If a center obstacle is not going to be created, either a top or bottom obstacle will be created. The
height of the obstacle is governed by a random value between obstacleHeightMin and
obstacleHeightMax . When obstacles are upgraded after 10 seconds, the height is increased by
obstcaleHeightIncrease until the height reaches obstcaleHeightLimit .
private var obstacleHeightMin:int = 40;
private var obstacleHeightMax:int = 60;
private var obstacleHeightLimit:int = 120;
private var obstacleHeightIncrease:int = 20;
Search WWH ::




Custom Search