Game Development Reference
In-Depth Information
The
render
function simply locks our canvas, loops through all of the game objects, and blits
them to the
canvasBitmapData
. The final task it completes is to make sure the
scrollRect
of the
canvasBitmap
is positioned in the right location to simulate scrolling.
Adding auxiliary functions
Many of the remaining auxiliary functions are very similar to ones you have seen in other games.
As usual, we will describe the major differences and new functions.
private function updateScoreBoard():void {
customScoreBoardEventScore.value = score.toString();
customScoreBoardEventShield.value =shield.toString()
customScoreBoardEventParticlePool.value = String(particleManager.particlePool.length);
customScoreBoardEventParticleActive.value = String(particleManager.particles.length);
customScoreBoardEventProjectilePool.value = String(projectileManager.
projectilePool.length);
customScoreBoardEventProjectileActive.value = String(projectileManager.
projectiles.length);
dispatchEvent(customScoreBoardEventScore);
dispatchEvent(customScoreBoardEventShield);
dispatchEvent(customScoreBoardEventParticlePool);
dispatchEvent(customScoreBoardEventParticleActive);
dispatchEvent(customScoreBoardEventProjectilePool);
dispatchEvent(customScoreBoardEventProjectileActive);
}
The
ScoreBoard
is updated using our new set of global custom
Events
.
private function addToScore(val:Number):void {
score += val;
}
The
addToScore
function simply accepts in a value to add to the current
score
.
private function circleCheck(x1:Number, x2:Number, y1:Number, y2:Number,
radius1:Number, radius2:Number):Boolean {
var dx:Number = x2 - x1;
var dy:Number = y2 - y1;
var dist:Number = Math.sqrt(dx * dx + dy * dy);
return dist < radius1 + radius2
}
The
circleCheck
function takes in the location of two objects and the radius of each. It returns
true
if they intersect, signaling a collision.
private function createExplode(xval:Number,yval:Number,parts:int):void {
for (var explodeCtr:int=0;explodeCtr<parts;explodeCtr++) {
particleManager.particlePoolCount = particleManager.particlePool.length-1;
if (particleManager.particlePoolCount > 0) {
tempParticle=particleManager.particlePool.pop();