Game Development Reference
In-Depth Information
}
private function addToScore(val:Number):void {
score += val;
}
Creating functions to fire missiles
The firePlayerMissile and fireMissileAtPlayer functions are very similar. They actually could
be combined into a single function with some modifications (for example, a switch:case
statement when a player or enemy fires a missile), but since they have slightly different jobs, we
have kept them separate. They both use the missileTime and missileDelay properties of the
TileByTileBlitSprite class to determine if the object trying to fire can actually fire. It does this
by comparing counting frame ticks with the TileByTileBlitSprite.missileTime . If the
missileTime is greater than the missileDelay value, a missile will be fired. All missiles are
instances of the BlitSprite class.
Once a missile is fired, its direction is set by the direction of the player or enemy firing the missile.
All player missiles travel at 3 pixels per frame tick. This pixel per frame rate can be modified to
come from a variable if you desire a power-up of some sort to make the player's missiles go
faster. The enemy missile speed is governed by the enemyShotSpeed for the lLevel class instance
The firePlayerMissile function is brand new. Copy it completely. The fireMissileAtPlayer
function already exists (as a stub with a trace).
private function firePlayerMissile():void {
if (player.missileTime++ > player.missileDelay) {
ammo--;
player.missileTime = 0;
//trace("fire a missile");
tempMissile = new BlitSprite(tileSheet, missileTiles, 0);
switch(player.rotation) {
case 0:
tempMissile.dx = 0;
tempMissile.dy = -3;
tempMissile.x = player.x;
tempMissile.y = player.y-10;
break
case 90:
tempMissile.x = player.x+10;
tempMissile.y = player.y;
tempMissile.dx = 3;
tempMissile.dy = 0;
break;
case 180:
tempMissile.x = player.x;
tempMissile.y = player.y+10;
tempMissile.dx = 0;
Search WWH ::




Custom Search