Exemplo n.º 1
0
    /// <summary>
    /// Sets the state of the Player
    /// </summary>
    /// <param name="state">Which state to set</param>
    /// <exception cref="ArgumentOutOfRangeException"></exception>
    public void SetState(PlayerStates state)
    {
        PlayerBaseState playerState;

        switch (state)
        {
        case PlayerStates.Shoot:
            playerState = new ShootingState(this);
            break;

        case PlayerStates.Walking:
            playerState = new WalkingState(this);
            break;

        case PlayerStates.Talking:
            playerState = new TalkingState(this);
            break;

        case PlayerStates.Win:
            playerState = new WinState(this);
            break;

        default:
            throw new ArgumentOutOfRangeException(nameof(state), state, null);
        }

        _currentState?.ExitState();

        _currentState = playerState;

        _currentState.EnterState();
    }
Exemplo n.º 2
0
    protected void SwitchState(PlayerBaseState newState)
    {
        // current state exits state
        ExitState();

        // new state enters state
        newState.EnterState();

        _ctx.CurrentState = newState;
    }
Exemplo n.º 3
0
    private void EnableNewState(PlayerBaseState state)
    {
        currentState = state;
        currentState.EnterState(this);
        //currentState.playerStateManager.gameObject.SetActive(true);
        currentState.playerStateManager.EnableCharacter(currentState.playerStateManager.gameObject);
        ShadeWhite(currentState.playerStateManager.spriteRenderer);

        coroutine = WaitAndRevert();
        StartCoroutine(coroutine);
    }
Exemplo n.º 4
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        //Debug.Log("Player hit collider: " + collision.gameObject.name);

        //if we hit spikes, change, update state and enter death state
        if (collision.gameObject.CompareTag("Spikes"))
        {
            _currentState = _states.Death();
            _currentState.EnterState();
        }
    }
Exemplo n.º 5
0
    public void TransitionToState(PlayerBaseState state)
    {
        if (freezePlayerState)
        {
            return;
        }

        currentState = state;
        currentState.EnterState(this);

        IfDebugPrintStates();
    }
Exemplo n.º 6
0
    protected void SwitchState(PlayerBaseState newState)
    {
        ExitStates();
        newState.EnterState();

        if (isRootState)
        {
            context.RootState = newState;
        }
        else if (currentSuperState != null)
        {
            currentSuperState.PassOnSubState(newState);
        }
    }
Exemplo n.º 7
0
    public void TransitionToStateInstantly(PlayerBaseState state)
    {
        rb.gravityScale = DefaultGravityScale;
        animFinished    = false;
        if (currentState != null)
        {
            currentState.playerStateManager.DisableCharacter(currentState.playerStateManager.gameObject);
        }

        currentState = state;
        currentState.EnterState(this);

        currentState.playerStateManager.EnableCharacter(currentState.playerStateManager.gameObject);
    }
Exemplo n.º 8
0
    public void TransitionToState(PlayerBaseState state)
    {
        if (isDying)
        {
            return;
        }
        currentState = state;
        currentState.EnterState(this);

        if (printDebugStates)
        {
            debugState = GetStateName();
            Debug.Log(debugState);
        }
    }
Exemplo n.º 9
0
    protected void SetSubState(PlayerBaseState newSubState)
    {
        if (currentSubState != null)
        {
            currentSubState.ExitStates();
        }

        if (newSubState == null)
        {
            currentSubState = null;
        }
        else
        {
            newSubState.EnterState();
            newSubState.SetSuperState(this);
            currentSubState = newSubState;
        }
    }
Exemplo n.º 10
0
    //public bool IsFalling { get { return _isFalling;  } }
    #endregion

    void Awake()
    {
        _playerControls = new PlayerControls();
        _rb             = GetComponent <Rigidbody2D>();
        _anim           = GetComponent <Animator>();
        ledgeInfo       = GetComponent <LedgeInformation>();
        audioManager    = FindObjectOfType <AudioManager>();
        ragdoll         = FindObjectOfType <RagdollController>();
        interact        = GetComponent <Interact>();

        //camera test
        camManager = FindObjectOfType <CameraManager>();

        //Controls calling OnMovement Input Function
        _playerControls.Gameplay.Move.started   += OnMovementInput;
        _playerControls.Gameplay.Move.canceled  += OnMovementInput;
        _playerControls.Gameplay.Move.performed += OnMovementInput;
        //_playerControls.Gameplay.Jump.started += OnJump; //Default
        //_playerControls.Gameplay.Jump.canceled += OnJump; //Default
        _playerControls.Gameplay.Jump.started  += ctx => OnJump();
        _playerControls.Gameplay.Jump.canceled += ctx => OnJumpReleased();

        _playerControls.Gameplay.Jetpack.performed += ctx => Thrust();
        _playerControls.Gameplay.Jetpack.canceled  += ctx => ThrustReleased();

        //Converting strings to hash is more performant
        _isGroundedHash = Animator.StringToHash("isGrounded");
        _isRunningHash  = Animator.StringToHash("isRunning");
        _isFallingHash  = Animator.StringToHash("isFalling");
        _jumpHash       = Animator.StringToHash("Jump");
        //speedXHash = Animator.StringToHash("SpeedX");

        // setup state
        _states = new PlayerStateFactory(this); // passes this PlayerStateMachine instance. PlayerStateFactory is expecting a PlayerStateMachine

        _currentState = _states.Idle();
        _currentState.EnterState();
    }
Exemplo n.º 11
0
 public void TransitionToState(PlayerBaseState state)
 {
     currentState = state;
     currentState.EnterState(this);
 }
Exemplo n.º 12
0
 public void TransitionToState(PlayerBaseState state)
 {
     //Store and set current concrete state
     currentState = state;          //set the state as the current state
     currentState.EnterState(this); //Activate the EnterState function of a new state for player avatar when a transition is triggered
 }
 public void TransitionToState(PlayerBaseState newState)
 {
     currentState = newState;
     PlayerEvents.CallPlayerChangedState(currentState);
     currentState.EnterState(this);
 }