Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            // Update input to allow states get player control etc.
            Input.Update();

            // Update exiting state if it is exiting
            if (ExitingState != null)
            {
                if (ExitingState.Status == GameStateStatus.Exiting)
                {
                    ExitingState.Update(gameTime);
                }
                else
                {
                    ExitingState = null;
                }
            }

            // Update the current state
            if (CurrentState != null)
            {
                CurrentState.Update(gameTime);
                // Handle input on current state only when it's running
                if (CurrentState.IsActive || CurrentState.IsPaused)
                {
                    CurrentState.HandleInput(this.Input);
                }

                if (PauseState != null && PauseState.IsActive)
                {
                    PauseState.Update(gameTime);
                }
            }
        }
Ejemplo n.º 2
0
 public void Update()
 {
     if (paused)
     {
         pauseState.Update();
     }
     else if (gameStates[currentState] != null)
     {
         gameStates[currentState].Update();
     }
 }
Ejemplo n.º 3
0
        public override void Update(GameTime gameTime)
        {
            _transition.Update(gameTime);

            if (_nextState != _currentState)
            {
                if (_transition.State == Transition.States.Waiting)
                {
                    _transition.Start();
                }

                if (_transition.State == Transition.States.FirstHalf)
                {
                    return;
                }

                // Change the state at the half-way point so it can't be seen
                if (_transition.State == Transition.States.Middle)
                {
                    _currentState = _nextState;
                }
            }

            switch (_currentState)
            {
            case States.Playing:

                if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape))
                {
                    _nextState = States.Paused;
                    return;
                }

                if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.M))
                {
                    _nextState = States.Map;
                    _mapState.UpdateMap(_currentArea, _player);
                    return;
                }

                if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.E))
                {
                    foreach (var entity in _currentArea.Interactables)
                    {
                        if (_player.CanInteract(entity))
                        {
                            var interactedComponent = entity.Components.GetComponent <InteractComponent>();
                            interactedComponent.OnInteract();
                        }
                    }
                }

                PlayerStateUpdate(gameTime);

                break;

            case States.Battle:

                _battleState.Update(gameTime);

                if (_battleState.BattleFinished)
                {
                    _nextState = States.AfterBattle;
                }

                break;

            case States.AfterBattle:

                _afterBattleState.Update(gameTime);

                if (_afterBattleState.Continue)
                {
                    _nextState = States.Playing;
                }

                break;

            case States.Paused:

                if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape))
                {
                    _nextState = States.Playing;
                    return;
                }

                _pauseState.Update(gameTime);

                break;

            case States.Map:

                if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape) ||
                    GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.M))
                {
                    _nextState = States.Playing;
                    return;
                }

                _mapState.Update(gameTime);

                break;

            default:
                throw new Exception("Unknown state: " + this._currentState.ToString());
            }
        }