Esempio n. 1
0
        /// <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();
        }