Beispiel #1
0
        /// <summary>
        /// Update the Environment each frame.
        /// </summary>
        /// <param name="elapsedTime">Time since last Update() call.</param>
        public override void Update(float elapsedTime)
        {
            // Toggle debug view = F1.
            if (Keyboard.GetState().IsKeyDown(Keys.F1) && !OldKeyboard.GetState().IsKeyDown(Keys.F1))
            {
                if (m_debugView != null)
                {
                    m_debugView = null;
                }
                else
                {
                    m_debugView = new Physics.DebugViewXNA(CollisionWorld);
                }
            }

            //Pause with Escape
            if (!paused)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Escape) && !OldKeyboard.GetState().IsKeyDown(Keys.Escape) ||
                    (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start) && !OldGamePad.GetState().IsButtonDown(Buttons.Start))
                    )
                {
                    pause(new GamePauseMenu(Controller, this));
                    Sound.PlayCue("scroll");
                }
            }

            // Debug Menu = F10.
            if (Keyboard.GetState().IsKeyDown(Keys.F10) && !OldKeyboard.GetState().IsKeyDown(Keys.F10))
            {
                Controller.ChangeEnvironment(new Menus.DebugMenu(Controller));
            }

            // Exit game.
            if (Keyboard.GetState().IsKeyDown(Keys.F5) && !OldKeyboard.GetState().IsKeyDown(Keys.F5))
            {
                Controller.Exit();
            }

            if (!paused)
            {
                HUD.enabled = true;
                if (elapsedTime > 0.0f)
                {
                    // Update physics.
                    CollisionWorld.Step(elapsedTime);

                    if (SpawnController != null)
                    {
                        SpawnController.Update(elapsedTime);
                    }

                    // Update entities.
                    Camera.Update(elapsedTime);
                    base.Update(elapsedTime);

                    // Particle keepalive.  Update remaining and try to remove if they are done.
                    ParticleKeepalive.RemoveAll(ent => {
                        ent.Update(elapsedTime);
                        if (ent.Effect.ActiveParticlesCount == 0)
                        {
                            ent.Remove();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    });
                }
            }
            else
            {
                Camera.Update(elapsedTime);
                m_popUp.Update(elapsedTime);
                HUD.enabled = false;
            }

            HUD.Update(elapsedTime);
            FadeOut.Update(elapsedTime);

            if (Balloon != null)
            {
                heatMultiplier = (this.ScreenVirtualSize.Y / 2 - Balloon.Position.Y) * 0.0007f;
            }
            else
            {
                heatMultiplier = 0;
            }
        }