Пример #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Try changing environment.
            if (m_nextEnv != null)
            {
                m_env.Dispose();
                m_env     = m_nextEnv;
                m_nextEnv = null;
            }

            // Game loop.
            Sound.Update();

            // Toggle fullscreen toggle with Alt+Enter.
            if ((Keyboard.GetState().IsKeyDown(Keys.LeftAlt) || Keyboard.GetState().IsKeyDown(Keys.RightAlt)) &&
                Keyboard.GetState().IsKeyDown(Keys.Enter) && !(
                    (OldKeyboard.GetState().IsKeyDown(Keys.LeftAlt) || OldKeyboard.GetState().IsKeyDown(Keys.RightAlt)) &&
                    OldKeyboard.GetState().IsKeyDown(Keys.Enter)))
            {
                IsFullscreen = !IsFullscreen;
            }



            m_env.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
            base.Update(gameTime);

            UpdateControls();

            // FPS counter.
            m_frameCounter++;
            m_frameTime += gameTime.ElapsedGameTime.TotalSeconds;
            if (m_frameTime >= 1.0f)
            {
                m_fps          = m_frameCounter;
                m_frameTime   -= 1.0f;
                m_frameCounter = 0;
                Window.Title   = "Case Sensitive (" + m_fps + " fps)";
            }
        }
Пример #2
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;
            }
        }