Exemplo n.º 1
0
        public void TransitionState(Player player)
        {
            // Interaction state changes have precendence over other state
            // changes, so they are checked before everything else.
            if (current == State.interacting)
            {
                if (player.InteractKeyPressed() && !player.TooFarFromInteractable())
                {
                    return;
                }
                player.EndInteract();
                current = State.initial;
            }
            else
            {
                if (player.InteractKeyPressed())
                {
                    var startedInteracting = player.TryBeginInteract();
                    if (startedInteracting)
                    {
                        current = State.interacting;
                        return;
                    }
                }
            }

            if (current == State.onGround)
            {
                if (player.JumpKeyPressed())
                {
                    current = State.jumping;
                    player.OnFirstFrameOfJump();
                    return;
                }
            }
            else if (current == State.jumping)
            {
                if (player.JumpTimeUp())
                {
                    if (player.JumpKeyPressed())
                    {
                        current = State.initial;
                        player.OnLastFrameOfJump();
                    }
                }
                else
                {
                    return;
                }
            }
            current = player.IsOnGround() ? State.onGround : State.inAir;
        }