Game Development Reference
In-Depth Information
percentage of the actual calculated distance we want each game object to move on
this frame tick, which is based on the results of the time-based step timer.
2. The player's ship shoots projectiles automatically. Projectiles are taken from the
projectileManager.projectilePool and fire from the ship's location every three
frames. The autoShoot function is called to fire the projectiles.
3. The player object is updated by passing in the current mouseX and mouseY values and a
delay value for the speed of the player relative to the mouse. The larger the delay
value, the slower the ship will follow the mouse.
4. Each mine's position is updated. Then, each mine's frame is updated by passing the
value 5 into the updateFrame function of the mine, which causes the mine to spin faster
by skipping 5 frames of animation on each frame. This 5 value is arbitrary. It simply
tells the Mine to rotate 5 degrees at a time. The value can be set to anything you like to
create different Mine spin rates.
5. The projectiles are updated.
6. If the player has exploded, the player's exploding particles are updated.
Notice that each of the update functions is passed the step value to use in calculating the
distance to move the object this frame tick.
Next up is the autoShoot function that is called on each frame tick. It will fire projectiles after a
three-frame delay automatically if there are any left in the projectileManager.projectilePool .
private function autoShoot(step:Number):void {
projectileManager.projectilePoolCount = projectileManager.projectilePool.length - 1;
mineManager.mineCount = mineManager.mines.length;
if (projectileManager.lastProjectileShot > 3 && projectileManager.projectilePoolCount
> 0 && playerStarted && mineManager.mineCount > 0) {
dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_PLAYER_SHOOT, false, 0, 8, 1));
tempProjectile = projectileManager.projectilePool.pop();
var projectileRadians:Number = (player.frame / 360) * 6.28;
//+ 16 to get it to the center
tempProjectile.x=(player.point.x+16)+Math.cos(projectileRadians);
tempProjectile.y =(player.point.y+16) + Math.sin(projectileRadians);
tempProjectile.x = player.x+16;
tempProjectile.y = player.y + 16;
tempProjectile.nextX = tempProjectile.x;
tempProjectile.nextY = tempProjectile.y;
tempProjectile.dx = rotationVectorList[player.frame].x;
tempProjectile.dy = rotationVectorList[player.frame].y;
tempProjectile.speed = 5;
tempProjectile.frame = 0;
tempProjectile.bitmapData = tempProjectile.animationList[0];
Search WWH ::




Custom Search