Exemplo 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)
        {
            switch (_currentState)
            {
            case GameState.IntroScreen:
                _introScreen.Update(gameTime);
                break;

            case GameState.MainMenu:
                SoundManager.PlayBGM("Call to Adventure");
                _mainMenu.Update(gameTime);
                break;

            case GameState.NewGame:
            case GameState.DemoMode:
                if (_overworld == null || _overworld.Parent == null)
                {
                    _loadingScreen.Update(gameTime);
                    break;
                }

                var player = _overworld.Players.First();
                //GameStateManager.DeleteAllSaves();
                LevelCollection.StoredWaypoints = new Dictionary <Entity, List <Waypoint> >
                {
                    { player, new List <Waypoint>() }
                };

                if (_currentState == GameState.DemoMode)
                {
                    GameStateManager.SelectSaveData(new Base.GameState
                    {
                        AllowWeapon = new List <string> {
                            "Sword", "Bow", "Boomerang", "FireWand"
                        },
                        DungeonsComplete = new List <string>(),
                        Player           = GameStateManager.GetPlayerState(player),
                        StoredWaypoints  = LevelCollection.StoredWaypoints[player]
                    });
                    player.AddWeapon(new Sword(), new Bow(), new Boomerang(), new FireWand());
                }
                else
                {
                    GameStateManager.SelectSaveData(new Base.GameState
                    {
                        AllowWeapon = new List <string> {
                            "Sword"
                        },
                        DungeonsComplete = new List <string>(),
                        Player           = GameStateManager.GetPlayerState(player),
                        StoredWaypoints  = LevelCollection.StoredWaypoints[player]
                    });
                }

                ChangeState(GameState.Playing);
                break;

            case GameState.Playing:
                if (_overworld != null)
                {
                    _overworld.Update(gameTime);
                }
                break;

            case GameState.LoadGame:
                _loadscreen.Update(gameTime);
                break;

            case GameState.LoadingGame:
                if (_overworld != null && _overworld.Parent != null)
                {
                    var loadingPlayer = _overworld.Players.First();
                    var playerState   = GameStateManager.CurrentState.Player;
                    var oldLevel      = loadingPlayer.CurrentLevel;

                    GameStateManager.LoadPlayerState(loadingPlayer);
                    if (oldLevel != playerState.CurrentLevel)
                    {
                        _overworld.GetLevel(oldLevel).RemoveEntity(loadingPlayer);
                        _overworld.GetLevel(loadingPlayer.CurrentLevel).AddEntity(loadingPlayer);
                    }
                    LevelCollection.StoredWaypoints = new Dictionary <Entity, List <Waypoint> > {
                        { loadingPlayer, GameStateManager.CurrentState.StoredWaypoints }
                    };
                    ChangeState(GameState.Playing);
                }
                else
                {
                    _loadingScreen.Update(gameTime);
                }
                break;

            case GameState.Options:
                _options.Update(gameTime);
                break;

            case GameState.Credits:
                _credits.Update(gameTime);
                break;

            case GameState.GameOver:
                _gameOver.Update(gameTime);
                break;

            case GameState.HowToPlay:
                _howToPlay.Update(gameTime);
                break;

            case GameState.Quiting:
                Exit();
                break;

            case GameState.Saving:
                _savescreen.Update(gameTime);
                break;
            }


            base.Update(gameTime);
        }