Game Development Reference
In-Depth Information
createExplode(EXPLODE_SMALL, tempMissile.x, tempMissile.y);
dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_HIT_WALL, false, 1, 0));
dispose(tempMissile);
}
}
//explosions can be updated and rendered at the same time
var explodeLength:int = explosionList.length - 1;
for (ctr = explodeLength; ctr >= 0; ctr--) {
tempExplode = explosionList[ctr];
tempExplode.animationLoop = true;
tempExplode.updateCurrentTile();
if (tempExplode.loopCounter > 0) {
explosionList.splice(ctr, 1);
dispose(tempExplode);
}else {
tempExplode.renderCurrentTile();
}
}
//** end added in the final Game.as
Adding the checkHitWall function
The checkHitWall function is used exclusively to test if missiles have hit a wall. It is much more
simple than the checkTileFunction , which requires a TileByTileBlitSprite . Since the missiles
use the BlitSprite class and do not need complicated AI movement logic, this function will be
much faster (in terms of code execution) than trying to shoehorn missile hitting tile code into the
checkTileFunction . It returns true if the current tile the missile is on is a TILE_WALL .
private function checkHitWall(object:BlitSprite):Boolean {
var row:int = int(object.nextY / tileWidth);
var col:int = int(object.nextX / tileHeight);
return tileSheetData[levelTileMap[row][col]] == TILE_WALL;
}
The checkCollisions function
The checkCollisions function is new; you have not seen it before at all. You have seen similar
functions in the last few chapters that do basically the same thing though—check for pixel-perfect
collisions between BitmapData instances inside sprites. One thing we have added in this chapter
is checking the nextX and nextY values rather than the current x and y values. While this check is
not completely necessary in an action game like No Tanks!, it is a good exercise to keep in mind.
If you do this, you will never have an instance where you move an object move too far in the
update function and need to move it back because of a collision.
Search WWH ::




Custom Search