/// <summary> /// Updates the background screen. Unlike most screens, this should not /// transition off even if it has been covered by another screen: it is /// supposed to be covered, after all! This overload forces the /// coveredByOtherScreen parameter to false in order to stop the base /// Update method wanting to transition off. /// </summary> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { if (ShowParticles) { addTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (addTimer > 0.25f) { addTimer -= 0.15f; particleSystems.Add(new ParticleSystem( new Vector2(random.Next(ScreenManager.GraphicsDevice.Viewport.Width), random.Next(ScreenManager.GraphicsDevice.Viewport.Height)), Vector2.Zero, 64, 256, 128, 1f + 2f * (float)random.NextDouble(), 0.05f, explosionColors)); } for (int i = 0; i < particleSystems.Count; i++) { particleSystems[i].Update((float)gameTime.ElapsedGameTime.TotalSeconds); if (particleSystems[i].IsActive == false) { particleSystems.Garbage.Add(particleSystems[i]); } } particleSystems.Collect(); } base.Update(gameTime, otherScreenHasFocus, false); }
/// <summary> /// Update the world simulation. /// </summary> /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param> public void Update(float elapsedTime) { // update all actors for (int i = 0; i < actors.Count; i++) { actors[i].Update(elapsedTime); } // update collision MoveWorld(elapsedTime); // update particle systems for (int i = 0; i < particleSystems.Count; i++) { particleSystems[i].Update(elapsedTime); if (particleSystems[i].IsActive == false) { particleSystems.Garbage.Add(particleSystems[i]); } } // update the starfield Vector2 starfieldTarget = Vector2.Zero; int playingPlayers = 0; for (int i = 0; i < ships.Length; i++) { if (ships[i].Playing) { starfieldTarget += ships[i].Position; playingPlayers++; } } if (playingPlayers > 0) { starfield.SetTargetPosition(starfieldTarget / playingPlayers); } starfield.Update(elapsedTime); // check if we can create a new power-up yet if (powerUpTimer > 0f) { powerUpTimer = Math.Max(powerUpTimer - elapsedTime, 0f); } if (powerUpTimer <= 0.0f) { SpawnPowerUp(); powerUpTimer = powerUpDelay; } // clean up the lists actors.Collect(); particleSystems.Collect(); }