public GlitchPlayerController(string TSID, GraphicsDevice _Device, int GroundHeight = 250)
 {
     Device = _Device;
     Character = new GlitchCharacter(TSID, _Device);
     Character.Location.X = _Device.Viewport.Width / 4;
     Character.Location.Y = _Device.Viewport.Height - GroundHeight;
     CurrentState = PlayerMoveState.Walking;
     ShadowBatch = new SpriteBatch(_Device);
     ShadowTex = GlitchRunnerGame.ContentManager.Load<Texture2D>("CharShadow");
 }
        private void DoInput()
        {
            if (StaleKeyboardState == null)
                StaleKeyboardState = Keyboard.GetState();

            if (Keyboard.GetState().IsKeyDown(Keys.Space) &&
                !StaleKeyboardState.IsKeyDown(Keys.Space) &&
                CurrentState == PlayerMoveState.Walking) {
                    CurrentState = PlayerMoveState.Jumping;
                    JumpStartLocation = Character.Location;
                    Direction = MOVE_UP;
                    Character.SetAnimation("jumpOver_test_sequence");
            }

            StaleKeyboardState = Keyboard.GetState();
        }
예제 #3
0
    private void UpdateGround()
    {
        Vector3 colSize        = model.GetComponent <BoxCollider>().size;
        bool    touchingGround = Physics.CheckBox(groundTransform.position, new Vector3(colSize.x / 2, groundHeight / 2, colSize.z / 2), transform.rotation, groundLayers);

        switch (moveState)
        {
        case PlayerMoveState.JUMP:
            if (rb.velocity.y < 0)
            {
                moveState = PlayerMoveState.FALLING;
            }
            break;

        case PlayerMoveState.FALLING:
            if (touchingGround || rb.velocity.y >= 0)
            {
                moveState = PlayerMoveState.IDLE;
            }
            break;

        default:
            if (!touchingGround)
            {
                moveState = PlayerMoveState.FALLING;
            }
            break;
        }

        switch (standState)
        {
        case PlayerStandState.GROUND:
            if (!touchingGround)
            {
                standState = PlayerStandState.AIR;
            }
            break;

        case PlayerStandState.AIR:
            if (touchingGround)
            {
                standState = PlayerStandState.GROUND;
            }
            break;
        }
    }
예제 #4
0
        public static void Initialize()
        {
            endTurnState           = new EndTurnState(playerTurnState);
            playerLandedState      = new PlayerLandedState(endTurnState);
            playerMoveState        = new PlayerMoveState(playerLandedState);
            playerRollState        = new PlayerRollState(playerMoveState);
            playerTurnState        = new PlayerTurnState(playerRollState);
            initialState           = new InitialState(playerTurnState);
            endTurnState.NextState = playerTurnState;

            States.Add("InitialState", initialState);
            States.Add("PlayerTurnState", playerTurnState);
            States.Add("PlayerRollState", playerRollState);
            States.Add("PlayerMoveState", playerMoveState);
            States.Add("PlayerLandedState", playerLandedState);
            States.Add("EndTurnState", endTurnState);
        }
    // Update is called once per frame
    void Update()
    {
        Debug.Log("Move State: " + moveState);
        Debug.Log("Action State: " + actionState);

        //checkDeath();

        //checkEndGame();

        if (actionState != PlayerActionState.Dead && player.clear == false)
        {
            //movestate will be updated before frame is rendered.
            //moveState = PlayerMoveState.Idle;
            //actionState = PlayerActionState.Idle;

            //checkCheat();

            cooldown();

            //apply horizontal movement and Jump when called
            ApplyMovement();

            //Apply Actions to Player when Called
            checkAction();

            updatePlayTime();

            checkPause();

            //check for ground when falling.
            if (!isGrounded)
            {
                if (rb2d.velocity.y <= 0)
                {
                    moveState = PlayerMoveState.Falling;
                    GroundCast();
                }

                else
                {
                    moveState = PlayerMoveState.Jumping;
                }
            }
        }
    }
예제 #6
0
    private void Awake()
    {
        StateMachine = new PlayerStateMachine();

        IdleState       = new PlayerIdleState(this, StateMachine, playerData, "idle");
        MoveState       = new PlayerMoveState(this, StateMachine, playerData, "move");
        JumpState       = new PlayerJumpState(this, StateMachine, playerData, "inAir");
        InAirState      = new PlayerInAirState(this, StateMachine, playerData, "inAir");
        LandState       = new PlayerLandState(this, StateMachine, playerData, "land");
        WallSlideState  = new PlayerWallSlideState(this, StateMachine, playerData, "wallSlide");
        WallGrabState   = new PlayerWallGrabState(this, StateMachine, playerData, "wallGrab");
        WallClimbState  = new PlayerWallClimbState(this, StateMachine, playerData, "wallClimb");
        WallJumpState   = new PlayerWallJumpState(this, StateMachine, playerData, "inAir");
        LedgeClimbState = new PlayerLedgeClimbState(this, StateMachine, playerData, "ledgeClimbState");
        DashState       = new PlayerDashState(this, StateMachine, playerData, "inAir");
        AttackState     = new PlayerAttackState(this, StateMachine, playerData, "attack1");
        AirAttackState  = new PlayerAirAttackState(this, StateMachine, playerData, "attack2");
    }
예제 #7
0
    //private void Update()
    //{
    //    var horizontal = Input.GetAxis("Horizontal");
    //    var vertical = Input.GetAxis("Vertical");
    //    var movement = new Vector3(horizontal, 0, vertical);


    //    animator.SetFloat("Speed", vertical);

    //    transform.Rotate(Vector3.up, horizontal * turnSpeed * Time.deltaTime);

    //    if (vertical != 0)
    //    {
    //        //Quaternion newDirection = Quaternion.LookRotation(movement);
    //        //transform.rotation = Quaternion.Slerp(transform.rotation,newDirection,Time.deltaTime*turnSpeed);
    //        float moveSpeedToUse = (vertical > 0) ? forwardMoveRunSpeed : backwardMoveSpeed;

    //        characterController.SimpleMove(transform.forward * moveSpeedToUse * vertical);
    //    }

    //}

    /// <summary>
    /// 角色移动方法
    /// </summary>
    /// <param name="moveSpeed">移动速度</param>
    /// <param name="moveState">移动状态</param>
    public void Move(float moveSpeed, PlayerMoveState moveState)
    {
        //如果移动状态为奔跑
        if (moveState == PlayerMoveState.Run)
        {
            //将射击设置为false,奔跑时不能射击
            animator.SetBool(ShootingID, false);
            animator.SetBool(IsSniperShootID, false);
            animator.SetFloat(RunSpeedID, GameManager.Instance.Vertical);
        }
        //如果移动状态为行走
        else if (moveState == PlayerMoveState.Walk)
        {
            //将射击设置为true
            if (GameManager.Instance.CurrentGun.gunName == GameManager.Instance.gunType.sniperRifle)
            {
                animator.SetBool(IsSniperShootID, true);
            }
            else
            {
                animator.SetBool(ShootingID, true);
            }
            animator.SetFloat(WalkSpeedID, GameManager.Instance.Vertical);
        }
        animator.SetFloat(HorizontalMoveSpeedID, GameManager.Instance.Horizontal);

        //transform.Rotate(Vector3.up, rotateSpeed * Time.deltaTime);
        Rotation();


        if (GameManager.Instance.Horizontal != 0 && GameManager.Instance.Vertical != 0)
        {
            characterController.SimpleMove(transform.right * GameManager.Instance.Horizontal * (GameManager.Instance.WalkSpeed / 2));
            characterController.SimpleMove(transform.forward * GameManager.Instance.Vertical * (moveSpeed / 2));
            return;
        }
        if (GameManager.Instance.Horizontal != 0 || GameManager.Instance.Vertical != 0)
        {
            characterController.SimpleMove(transform.right * GameManager.Instance.Horizontal * GameManager.Instance.WalkSpeed);
            characterController.SimpleMove(transform.forward * GameManager.Instance.Vertical * moveSpeed);
        }
    }
예제 #8
0
    private void Awake()
    {
        StateMachine = new PlayerStateMachine();

        IdleState            = new PlayerIdleState(this, StateMachine, playerData, "idle");
        MoveState            = new PlayerMoveState(this, StateMachine, playerData, "move");
        JumpState            = new PlayerJumpState(this, StateMachine, playerData, "inAir");
        InAirState           = new PlayerInAirState(this, StateMachine, playerData, "inAir");
        LandState            = new PlayerLandState(this, StateMachine, playerData, "land");
        WallClimbState       = new PlayerWallClimbState(this, StateMachine, playerData, "wallClimb");
        WallGrabState        = new PlayerWallGrabState(this, StateMachine, playerData, "wallGrab");
        WallSlideState       = new PlayerWallSlideState(this, StateMachine, playerData, "wallSlide");
        WallJumpState        = new PlayerWallJumpState(this, StateMachine, playerData, "inAir");
        LedgeClimbState      = new PlayerLedgeClimbState(this, StateMachine, playerData, "ledgeClimbState");
        DashState            = new PlayerDashState(this, StateMachine, playerData, "inAir");
        CrouchIdleState      = new PlayerCrouchIdleState(this, StateMachine, playerData, "crouchIdle");
        CrouchMoveState      = new PlayerCrouchMoveState(this, StateMachine, playerData, "crouchMove");
        PrimaryAttackState   = new PlayerAttackState(this, StateMachine, playerData, "attack");
        SecondaryAttackState = new PlayerAttackState(this, StateMachine, playerData, "attack");
    }
예제 #9
0
    public CharacterStateMachine(PlayerController player)
    {
        _player = player;
        CharacterState.Init(player);

        PlayerIdleState      idleState   = new PlayerIdleState();
        PlayerMoveState      moveState   = new PlayerMoveState();
        PlayerAimState       aimState    = new PlayerAimState();
        PlayerAttackingState attackState = new PlayerAttackingState();

        idleState.InitTransitions(moveState, aimState);
        moveState.InitTransitions(idleState, attackState, aimState);
        aimState.InitTransitions(moveState, attackState, idleState);
        attackState.InitTransitions(moveState);

        _allStates.Add(idleState.GetType(), idleState);
        _allStates.Add(moveState.GetType(), moveState);

        _currentState = idleState;
    }
예제 #10
0
    private void Awake()
    {
        FiniteStateMachine = new PlayerFiniteStateMachine();

        IdleState = new PlayerIdleState(this, FiniteStateMachine, _playerData, "idle");
        MoveState = new PlayerMoveState(this, FiniteStateMachine, _playerData, "move");

        LandState  = new PlayerLandState(this, FiniteStateMachine, _playerData, "land");
        JumpState  = new PlayerJumpState(this, FiniteStateMachine, _playerData, "inAir");
        InAirState = new PlayerInAirState(this, FiniteStateMachine, _playerData, "inAir");

        WallSlideState  = new PlayerWallSlideState(this, FiniteStateMachine, _playerData, "wallSlide");
        WallGrabState   = new PlayerWallGrabState(this, FiniteStateMachine, _playerData, "wallGrab");
        WallClimbState  = new PlayerWallClimbState(this, FiniteStateMachine, _playerData, "wallClimb");
        WallJumpState   = new PlayerWallJumpState(this, FiniteStateMachine, _playerData, "inAir");
        LedgeClimbState = new PlayerLedgeClimbState(this, FiniteStateMachine, _playerData, "ledgeClimbState");

        DashState = new PlayerDashState(this, FiniteStateMachine, _playerData, "inAir");

        CrouchIdleState = new PlayerCrouchIdleState(this, FiniteStateMachine, _playerData, "crouchIdle");
        CrouchMoveState = new PlayerCrouchMoveState(this, FiniteStateMachine, _playerData, "crouchMove");

        OnRopeStateAim    = new PlayerOnRopeState_Aim(this, FiniteStateMachine, _playerData, "idle");
        OnRopeStateAttach = new PlayerOnRopeState_Attach(this, FiniteStateMachine, _playerData, "inAir");
        OnRopeStateMove   = new PlayerOnRopeState_Move(this, FiniteStateMachine, _playerData, "inAir");
        OnRopeStateFinish = new PlayerOnRopeState_Finish(this, FiniteStateMachine, _playerData, "inAir");

        // TODO: Attack states using unnecessary Player Data
        SwordAttackState01 = new PlayerSwordAttackState_01(this, FiniteStateMachine, _playerData, "swordAttack01", _swordAttackPosition01,
                                                           _playerSwordAttackData01);
        SwordAttackState02 = new PlayerSwordAttackState_02(this, FiniteStateMachine, _playerData, "swordAttack02", _swordAttackPosition02,
                                                           _playerSwordAttackData02);
        SwordAttackState03 = new PlayerSwordAttackState_03(this, FiniteStateMachine, _playerData, "swordAttack03", _swordAttackPosition03,
                                                           _playerSwordAttackData03);
        FireArrowShotStateStart = new PlayerBowFireArrowShotState_Start(this, FiniteStateMachine, _playerData, "bowFireShotStart",
                                                                        _fireArrowShotAttackPosition, _playerFireArrowShotData);
        FireArrowShotStateAim = new PlayerBowFireArrowShotState_Aim(this, FiniteStateMachine, _playerData, "bowFireShotAim",
                                                                    _fireArrowShotAttackPosition, _playerFireArrowShotData);
        FireArrowShotStateFinish = new PlayerBowFireArrowShotState_Finish(this, FiniteStateMachine, _playerData, "bowFireShotFinish",
                                                                          _fireArrowShotAttackPosition, _playerFireArrowShotData);
    }
        private void Awake()
        {
            _stateMachine    = new PlayerStateMachine();
            CombatController = new CombatController();

            IdleState        = new PlayerIdleState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_IDLE_2_HASH);
            MoveState        = new PlayerMoveState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_RUN_2_HASH);
            JumpState        = new PlayerJumpState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_JUMP_HASH);
            InAirState       = new PlayerInAirState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_AIR_HASH);
            LandState        = new PlayerLandState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_LAND_HASH);
            WallSlideState   = new PlayerWallSlideState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_WALL_SLIDING_HASH);
            LedgeClimbState  = new PlayerLedgeClimbState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_LEDGE_GRAB_HASH);
            LedgeJumpState   = new PlayerLedgeJumpState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_LEDGE_JUMP_HASH);
            CrouchIdleState  = new PlayerCrouchIdleState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_CROUCH_IDLE_HASH);
            CrouchMoveState  = new PlayerCrouchMoveState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_CROUCH_WALK_HASH);
            SwordAttackState = new PlayerSwordAttackState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_ATTACK_1_HASH, 3);
            HandAttackState  = new PlayerHandAttackState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_PUNCH_1_HASH, 5);
            AirAttackState   = new PlayerAirAttackState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_AIR_ATTACK_1_HASH, 2);
            SlideState       = new PlayerSlideState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_SLIDE_HASH);
            ItemState        = new PlayerItemState(this, _stateMachine, _playerData, AnimationConstants.PLAYER_USE_ITEM_HASH);
        }
    public void cooldown()
    {
        if (dashLength > 0.0f)
        {
            dashLength -= Time.deltaTime;

            if (dashLength <= 0.0f)
            {
                moveState        = PlayerMoveState.Idle;
                player.isDashing = false;
            }
        }

        if (dashTimer > 0.0f)
        {
            dashTimer -= Time.deltaTime;
        }

        if (attackTimer > 0.0f)
        {
            attackTimer -= Time.deltaTime;

            if (attackTimer <= 0.0f)
            {
                actionState = PlayerActionState.Idle;
            }
        }

        if (duckTimer > 0.0f)
        {
            duckTimer -= Time.deltaTime;

            if (duckTimer <= 0.0f)
            {
                blockArea.enabled = true;
                duckTimer         = 0.25f;
            }
        }
    }
예제 #13
0
    private void Awake()
    {
        playerStateMachine = new PlayerStateMachine();

        playerIdleState = new PlayerIdleState(this, playerData, "idle");
        playerMoveState = new PlayerMoveState(this, playerData, "move");
        playerLandState = new PlayerLandState(this, playerData, "land");

        playerJumpState    = new PlayerJumpState(this, playerData, "inAir");
        playerDashState    = new PlayerDashState(this, playerData, "dash");
        playerAttack1State = new PlayerAttack1State(this, playerData, "attack1");
        playerAttack2State = new PlayerAttack2State(this, playerData, "attack2");

        playerPrimaryAttackState   = new PlayerAttackState(this, playerData, "attack");
        playerSecondaryAttackState = new PlayerAttackState(this, playerData, "attack");

        playerInAirState = new PLayerInAirState(this, playerData, "inAir");

        playerAttackedState = new PlayerAttackedState(this, playerData, "attacked");

        playerDeathState = new PlayerDeathState(this, playerData, "die");
    }
예제 #14
0
    /// <summary>
    /// Determine the player move state based upon the current player overall state.
    /// </summary>
    private void DeterminePlayerMoveState()
    {
        // Calculate Character Status
        if (!previouslyGrounded && characterController.isGrounded)
        {
            if (fallingTimer > 0.5f) // TODO: create method will good name
            // TODO: Play Landing Sound
            {
            }

            moveDirection.y = 0f;
            isJumping       = false;
            moveState       = PlayerMoveState.Landing;
        }
        else if (!characterController.isGrounded)
        {
            moveState = PlayerMoveState.NotGrounded;
        }
        else if (characterController.velocity.sqrMagnitude < 0.01f)
        {
            moveState = PlayerMoveState.NotMoving;
        }
        else if (isCrouching)
        {
            moveState = PlayerMoveState.Crouching;
        }
        else if (isWalking)
        {
            moveState = PlayerMoveState.Walking;
        }
        else
        {
            moveState = PlayerMoveState.Running;
        }

        previouslyGrounded = characterController.isGrounded;
    }
예제 #15
0
    private void Jump()
    {
        if (standState == PlayerStandState.AIR)
        {
            return;
        }
        PlayerInput input = GetInput();

        if (!input.jump)
        {
            return;
        }
        if (rb.velocity.y > 0)
        {
            return;
        }
        if (!Physics.Raycast(groundTransform.position, -transform.up, groundHeight))
        {
            return;
        }
        rb.AddForce(jumpForce * transform.up, ForceMode.Impulse);
        moveState = PlayerMoveState.JUMP;
        anim.Play("Jump");
    }
예제 #16
0
    private void Awake()
    {
        //Awake handles one time instatiation of the state machine and state components
        //Super States do not need to be instatiated
        StateMachine = new PlayerStateMachine();

        IdleState             = new PlayerIdleState(this, StateMachine, playerData, "idle");
        MoveState             = new PlayerMoveState(this, StateMachine, playerData, "move");
        TurnState             = new PlayerTurnState(this, StateMachine, playerData, "turn");
        JumpSquatState        = new PlayerJumpSquatState(this, StateMachine, playerData, "jumpSquat");
        JumpState             = new PlayerJumpState(this, StateMachine, playerData, "jump");
        InAirState            = new PlayerInAirState(this, StateMachine, playerData, "inAir");
        LandState             = new PlayerLandState(this, StateMachine, playerData, "land");
        DiveState             = new PlayerDiveState(this, StateMachine, playerData, "dive");
        DoubleJumpState       = new PlayerDoubleJumpState(this, StateMachine, playerData, "doubleJump");
        EndFallState          = new PlayerEndFallState(this, StateMachine, playerData, "endFall");
        StartFallState        = new PlayerStartFallState(this, StateMachine, playerData, "startFall");
        AbilityOneState       = new PlayerAbilityOneState(this, StateMachine, playerData, "abilityOne");
        CrouchState           = new PlayerCrouchState(this, StateMachine, playerData, "crouch");
        AbilityCrouchOneState = new PlayerAbilityCrouchOneState(this, StateMachine, playerData, "abilityCrouchOne");
        AbilityJumpOneState   = new PlayerAbilityJumpOneState(this, StateMachine, playerData, "abilityJumpOne");
        DodgeState            = new PlayerDodgeState(this, StateMachine, playerData, "dodge");
        AbilityTwoState       = new PlayerAbilityTwoState(this, StateMachine, playerData, "abilityTwo");
    }
예제 #17
0
    private void Awake()
    {
        StateMachine = new PlayerStateMachine();


        IdleState       = new PlayerIdleState(this, StateMachine, playerData, "idle");
        MoveState       = new PlayerMoveState(this, StateMachine, playerData, "move");
        JumpState       = new PlayerJumpState(this, StateMachine, playerData, "inAir");
        InAirState      = new PlayerInAirState(this, StateMachine, playerData, "inAir");
        LandState       = new PlayerLandState(this, StateMachine, playerData, "land");
        WallSlideState  = new PlayerWallSlideState(this, StateMachine, playerData, "wallSlide");
        WallGrabState   = new PlayerWallGrabState(this, StateMachine, playerData, "wallGrab");
        WallClimbState  = new PlayerWallClimbState(this, StateMachine, playerData, "wallClimb");
        WallJumpState   = new PlayerWallJumpState(this, StateMachine, playerData, "inAir");
        LedgeClimbState = new PlayerLedgeClimbState(this, StateMachine, playerData, "ledgeClimbState");
        DashState       = new PlayerDashState(this, StateMachine, playerData, "inAir");
        CrouchIdleState = new PlayerCrouchIdleState(this, StateMachine, playerData, "crouchIdle");
        CrouchMoveState = new PlayerCrouchMoveState(this, StateMachine, playerData, "crouchMove");
        InjuredState    = new PlayerInjuredState(this, StateMachine, playerData, "injured");
        DeadState       = new PlayerDeadState(this, StateMachine, playerData, "dead");
        KickState       = new PlayerKickState(this, StateMachine, playerData, "kick");
        SlideKickState  = new PlayerSlideKickState(this, StateMachine, playerData, "slideKick");
        RollState       = new PlayerRollState(this, StateMachine, playerData, "roll");
    }
    public void ApplyMovement()
    {
        //horizontal movement uses 'Get Axis' to interpolate up to full speed when walking.
        //Also allows for variable movement speed when using Joysticks

        Debug.Log("Horizontal Axis: " + Input.GetAxis("Horizontal"));
        Debug.Log("Vertical Axis: " + Input.GetAxis("Vertical"));

        bool lastFacingRight = player.facingRight;

        if (Input.GetAxis("Horizontal") < 0 && lastFacingRight)
        {
            player.facingRight = false;
            charMove.flipChar(this.gameObject);
        }
        else if (Input.GetAxis("Horizontal") > 0 && !lastFacingRight)
        {
            player.facingRight = true;
            charMove.flipChar(this.gameObject);
        }

        if (moveState != PlayerMoveState.Dashing)
        {
            rb2d.velocity = new Vector2(Input.GetAxis("Horizontal") * player.speed, rb2d.velocity.y);
            Debug.Log("Player Moving");

            if (Input.GetAxis("Horizontal") != 0)
            {
                moveState = PlayerMoveState.Running;
            }
            else
            {
                moveState = PlayerMoveState.Idle;
            }

            if (Input.GetAxis("Vertical") < 0.0f && moveState != PlayerMoveState.Falling)
            {
                moveState = PlayerMoveState.Crouching;

                Debug.DrawRay(new Vector2(transform.position.x, transform.position.y - 0.8f), Vector3.down * vertRange, Color.red);
                RaycastHit2D[] hit2D = Physics2D.RaycastAll(new Vector2(transform.position.x, transform.position.y - 0.8f), Vector2.down, vertRange);

                if (hit2D != null)
                {
                    for (int i = 0; i < hit2D.Length; i++)
                    {
                        Debug.Log("Trying to Duck. Standing On: " + hit2D[i].collider.tag);

                        if (hit2D[i].collider.tag == "platform")
                        {
                            blockArea.enabled = false;
                            duckTimer         = 0.05f;
                            break;
                        }
                    }
                }
            }

            //rigidbody gravity will handle most downwards movement!
            //Use Jump to add velocity upwards.
            if ((Input.GetKeyDown(jumpKey) || Input.GetKeyDown(joyJumpKey)) && moveState != PlayerMoveState.Crouching)
            {
                if (isGrounded && !isStunned)
                {
                    moveState      = PlayerMoveState.Jumping;
                    rb2d.velocity += Vector2.up * player.jumpForce;
                    isGrounded     = false;
                }
            }
        }
        else
        {
            if (dashRight)
            {
                rb2d.velocity = Vector2.right * player.dashSpeed;
            }
            else
            {
                rb2d.velocity = Vector2.left * player.dashSpeed;
            }
        }

        //if stunned, overwrite movement
        if (isStunned)
        {
            rb2d.velocity = new Vector2(0, rb2d.velocity.y);
        }

        if ((Input.GetKeyDown(dashKey) || Input.GetKeyDown(joyDashKey)) && dashTimer <= 0.0f)
        {
            moveState        = PlayerMoveState.Dashing;
            player.isDashing = true;
            dashLength       = player.dashDelay;
            dashTimer        = player.dashTime;

            if (Input.GetAxis("Horizontal") > 0)
            {
                dashRight = true;
            }
            else if (Input.GetAxis("Horizontal") < 0)
            {
                dashRight = false;
            }
            else
            {
                if (player.facingRight)
                {
                    dashRight = false;
                }
                else
                {
                    dashRight = true;
                }
            }
        }
    }
예제 #19
0
 public void SetMoveState(PlayerMoveState set)
 {
     moveState = set;
 }
예제 #20
0
 public void SetPlayerMoveState(PlayerMoveState _state)
 {
     playerMoveState = _state;
 }
        private void DoJumpingLogic()
        {
            if (CurrentState != PlayerMoveState.Jumping)
                return;

            if (JumpStartLocation.Y - Character.Location.Y > JumpHeight) {
                Direction = MOVE_DOWN;
            }

            if (Character.Location.Y > JumpStartLocation.Y)
            {
                Character.Location.Y = JumpStartLocation.Y;
                CurrentState = PlayerMoveState.Walking;
                Character.SetAnimation("walk2x");
                Direction = 0;
                GlitchRunnerGame.ParticleManager.SpawnSmokeParticles(new Vector2(Character.FootBoundingBox.X + (Character.FootBoundingBox.Width / 2)
                    , Character.FootBoundingBox.Y + Character.FootBoundingBox.Height), 4, 25);
            }
        }
예제 #22
0
    /// <summary>
    /// 初始化状态机
    /// 状态和转换条件在这统一初始化添加
    /// 默认 除了skill和fight状态 其余状态要切换到其他状态的时候 要先切换到idle状态
    /// </summary>
    protected override void InitStateMachine()
    {
        stateDic   = new Dictionary <StateID, FSMState>();
        m_FSM      = new FSMSystem();
        idleState  = new PlayerIdleState();
        moveState  = new PlayerMoveState();
        fightState = new PlayerFightState();
        skillState = new PlayerSkillState();


        //attr = player.GetComponent<AttrController>();
        m_FSM.attr = attr;

        m_FSM.AddState(idleState, this);
        stateDic.Add(idleState.ID, idleState);
        idleState.AddTransition(Transition.IsIdle, StateID.Idle);
        idleState.AddTransition(Transition.IsMove, StateID.Move);
        idleState.AddTransition(Transition.IsDeath, StateID.Death);
        idleState.AddTransition(Transition.IsFight, StateID.Fight);
        idleState.AddTransition(Transition.IsCast_Skill, StateID.Cast_Skill);
        idleState.AddTransition(Transition.IsRiding, StateID.Riding);
        idleState.AddTransition(Transition.IsVigilance, StateID.Vigilance);
        idleState.AddTransition(Transition.IsChatStart, StateID.ChatStart);
        idleState.AddTransition(Transition.IsChatEnd, StateID.ChatEnd);


        m_FSM.AddState(moveState, this);
        stateDic.Add(moveState.ID, moveState);
        moveState.AddTransition(Transition.IsIdle, StateID.Idle);

        m_FSM.AddState(fightState, this);
        stateDic.Add(fightState.ID, fightState);
        fightState.AddTransition(Transition.IsIdle, StateID.Idle);
        fightState.AddTransition(Transition.IsCast_Skill, StateID.Cast_Skill);
        fightState.AddTransition(Transition.IsMove, StateID.Move);

        m_FSM.AddState(skillState, this);
        stateDic.Add(skillState.ID, skillState);
        skillState.AddTransition(Transition.IsIdle, StateID.Idle);
        skillState.AddTransition(Transition.IsFight, StateID.Fight);

        //初始状态分主城(Idle)和地下城(Fight)
        //设置初始状态(idle状态)

        if (AttrController.Instance.Fight())
        {
            m_FSM.SetCurrentState(fightState);
            m_FSM.CurrentState.m_MyJoystick = ETCInput.GetControlJoystick("MyJoystick");
            //m_FSM.attr.StartCoroutine(fightState.DoLogic());
        }
        else
        {
            m_FSM.SetCurrentState(idleState);
            m_FSM.CurrentState.m_MyJoystick = ETCInput.GetControlJoystick("MyJoystick");
        }
        //m_FSM.attr.StartCoroutine(idleState.DoLogic());
        //idleState.RunLogic();

        //测试战斗状态
        //m_FSM.SetCurrentState(fightState);
        //m_FSM.CurrentState.m_MyJoystick = ETCInput.GetControlJoystick("MyJoystick");
        //m_FSM.attr.StartCoroutine(fightState.DoLogic());
    }
예제 #23
0
 public void EndWallRunningOrClimbing()
 {
     _playerMoveState = PlayerMoveState.Walking;
 }
예제 #24
0
    private void Update()
    {
        // We don't do anything else if we are busy in the dressing room
        if (_playerMoveState == PlayerMoveState.BusyDressing)
        {
            return;
        }

        // We don't do anything else if we are inside a vehicle
        if (_player.PlayerVehicle.BusyWithVehicle)
        {
            _playerMoveState = PlayerMoveState.BusyWithVehicle;

            return;
        }

        // If we are wall running, we don't have to check for other states
        if (GameManager.Instance.InputManager.Rushing && IsBusyWithWall && _player.PlayerWallRun.CanWallRun && Mathf.Abs(GameManager.Instance.InputManager.Horizontal) > 0)
        {
            _playerMoveState = PlayerMoveState.WallRunning;

            return;
        }
        else
        {
            // If we aren't wall running anymore, but were in wall running mode, then we try to climb again if possible, or go back to normal mode
            if (_playerMoveState == PlayerMoveState.WallRunning && _player.PlayerWallRun.CanWallRun)
            {
                // If we stopped wall running, but we were in the wall run state and can still potentially wall run (means we have something to climb on)
                // We go back to climbing
                _player.PlayerWallRun.BackToClimb();
                _playerMoveState = PlayerMoveState.WallClimbing;
            }
            // We go back to current mode when we aren't wall running or wall climbing
            if (_playerMoveState != PlayerMoveState.WallClimbing && _playerMoveState != PlayerMoveState.InteractingWithItem)
            {
                _playerMoveState = _modes[_currentMode].DefaultMoveState;
            }
        }

        // We only listen to changes in move state when we aren't busy with wall and when we aren't using an item
        // And when we aren't recovering energy
        if (_playerMoveState != PlayerMoveState.WallClimbing &&
            _playerMoveState != PlayerMoveState.WallRunning &&
            _playerMoveState != PlayerMoveState.InteractingWithItem &&
            !_player.PlayerStatus.IsRecoveringEnergy)
        {
            if (GameManager.Instance.InputManager.Rushing)
            {
                _playerMoveState = _modes[_currentMode].RushMoveState;
            }
            else
            {
                _playerMoveState = _modes[_currentMode].DefaultMoveState;
            }
        }

        // Preparing and unpreparing weapon
        if (GameManager.Instance.InputManager.PreparedOrUnprepareWeapon && !IsBusyWithWall && !_player.PlayerPickAnimator.HoldingItem)
        {
            if (_playerWeaponState != PlayerWeaponState.Prepared &&
                _player.PlayerWeapons.EquippedWeaponMount != null &&
                _player.PlayerWeapons.EquippedWeaponMount.Weapon.WeaponType != WeaponType.Hands)
            {
                _playerWeaponState = PlayerWeaponState.Prepared;
            }
            else
            {
                _playerWeaponState = PlayerWeaponState.Unprepared;
            }
        }

        // Begin Climb
        // Can't climb if we are holding an item
        // Can't climb if we are recovering energy
        if (GameManager.Instance.InputManager.WallClimb &&
            !_player.PlayerPickAnimator.HoldingItem &&
            !_player.PlayerStatus.IsRecoveringEnergy)
        {
            if (_playerMoveState != PlayerMoveState.WallClimbing && _player.PlayerWallClimb.CanBeginClimb)
            {
                _playerWeaponState = PlayerWeaponState.Unprepared;
                _playerMoveState   = PlayerMoveState.WallClimbing;
                _player.PlayerWallClimbAnimator.StartClimb();
            }
            else
            {
                if (_playerMoveState == PlayerMoveState.WallClimbing)
                {
                    _player.AnimatorSounds.PlayJumpSound();
                    _player.PlayerAnimator.Animator.SetTrigger("StopWallClimbing");
                }
                _playerMoveState = _modes[_currentMode].DefaultMoveState;
            }
        }

        // Change Move State
        if (GameManager.Instance.InputManager.ChangeMode)
        {
            _currentMode++;
            if (_currentMode >= _modes.Count)
            {
                _currentMode = 0;
            }
        }

        // Forcing states when tired (recovering energy)
        if (_player.PlayerStatus.IsRecoveringEnergy)
        {
            _currentMode = 0;
            if (IsMakingEffort)
            {
                _playerMoveState = PlayerMoveState.Walking;
            }
        }
    }