/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { if (Alive) { // Will wait a certain time before bringing the ship back on screen. if (ship.MovedOut(currentDir)) { betweenAppearances = new TimeSpan(0, 0, 0, randomize.Next(2, 10)); if (gameTime.TotalGameTime - lastAppearance > betweenAppearances) { if (currentDir == Direction.RIGHT) { currentDir = Direction.LEFT; } else { currentDir = Direction.RIGHT; } ship.Move(currentDir); } } else { ship.Move(currentDir); lastAppearance = gameTime.TotalGameTime; } bomb.Launch(Boundary, gameTime); } base.Update(gameTime); }
/// <summary> /// This selects at random an alien and then lauches a projectile from its /// position if it is alive. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values</param> private void generateProjectile(GameTime gameTime) { int alien = alienBombing.Next(0, aliens.Length - 1); if (this[alien].Alive) { bomb.Launch(this[alien].Boundary, gameTime); } }
/// <summary> /// Launches the bonus bomb. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { if (gameTime.TotalGameTime - lastBonus > BETWEEN_BONUSES) { if (randomize.Next(1, 1000) == 1) { bomb.Launch(new Rectangle(randomize.Next (0, game.GraphicsDevice.Viewport.Width), 10, 1, 1), gameTime); lastBonus = gameTime.TotalGameTime; } } base.Update(gameTime); }