Esempio n. 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)
        {
            FilteredInputListener.Update(gameTime);

            if (GameState != GameStates.Paused)
            {
                if (FilteredInputListener.WasKeyPressed(Keys.Escape))
                {
                    GameState = GameStates.Paused;
                    FilteredInputListener.ResetKey(Keys.Escape);
                }

                if (GameState == GameStates.Normal)
                {
                    var modeState = CurrentGameMode.Update(gameTime);
                    PhysicsWorld.Step(1.0f / 120.0f, 1, 1);
                    if (Player.LivesRemaining <= 0)
                    {
                        Exit();
                    }

                    if (modeState != GameModeStatus.Continue)
                    {
                        LastRespawnTime = gameTime.TotalGameTime;
                        GameState       = GameStates.WaitingForRespawn;
                    }
                }
                else if (GameState == GameStates.WaitingForRespawn)
                {
                    var timeWaited = gameTime.TotalGameTime - LastRespawnTime;
                    if (timeWaited >= RespawnWaitTime)
                    {
                        GameState = GameStates.Normal;
                        Player.Reset();
                        CurrentGameMode.Spawn();
                    }
                }

                base.Update(gameTime);
            }
            else
            {
                if (FilteredInputListener.WasKeyPressed(Keys.Escape))
                {
                    GameState = GameStates.Normal;
                    FilteredInputListener.ResetKey(Keys.Escape);
                }
                else
                {
                    var menuResult = CurrentMenu.Update(gameTime);
                    if (menuResult != null)
                    {
                        if (menuResult.Action == MenuAction.Navigate)
                        {
                            CurrentMenu = Container.Resolve <MenuFactory>().Get(menuResult.NextMenuName);
                        }
                        else if (menuResult.Action == MenuAction.NewGame)
                        {
                            Player.SetUpForNewGame();
                            CurrentGameMode.SetUpForNewGame();
                        }
                        else if (menuResult.Action == MenuAction.QuitGame)
                        {
                            GameWorld.SetUpForNewGame();
                            Exit();
                        }
                    }
                }
            }
        }