Пример #1
0
    // Update is called once per frame
    void Update()
    {
        // use last state to restore some ladder specific values
        if (_motor.motorState != PlatformerMotor2D.MotorState.FreedomState)
        {
            // try to restore, sometimes states are a bit messy because change too much in one frame
            FreedomStateRestore(_motor);
        }

        // JUMP?
        // If you want to jump in ladders, leave it here, otherwise move it down
        if (CrossPlatformInputManager.GetButtonDown(PC2D.Input.JUMP))
        {
            _motor.Jump();
            _motor.DisableRestrictedArea();

            JumpCounter.instance.DiscountJump();

            GameObject.Find("AudioManager").GetComponent <AudioManager>().Play("Jump");
        }

        // ATACK
        // if (Input.GetButtonDown("Fire1"))
        // {
        //  gameObject.GetComponent<PC2D.PlatformerAnimation2D>().Attack();
        // }

        _motor.jumpingHeld = CrossPlatformInputManager.GetButton(PC2D.Input.JUMP);

        // XY freedom movement
        if (_motor.motorState == PlatformerMotor2D.MotorState.FreedomState)
        {
            _motor.normalizedXMovement = CrossPlatformInputManager.GetAxis(PC2D.Input.HORIZONTAL);
            _motor.normalizedYMovement = CrossPlatformInputManager.GetAxis(PC2D.Input.VERTICAL);

            return; // do nothing more
        }

        // X axis movement
        if (Mathf.Abs(CrossPlatformInputManager.GetAxis(PC2D.Input.HORIZONTAL)) > PC2D.Globals.INPUT_THRESHOLD)
        {
            _motor.normalizedXMovement = CrossPlatformInputManager.GetAxis(PC2D.Input.HORIZONTAL);
        }
        else
        {
            _motor.normalizedXMovement = 0;
        }

        // Y axis movement
        if (CrossPlatformInputManager.GetAxis(PC2D.Input.VERTICAL) != 0)
        {
            bool up_pressed = CrossPlatformInputManager.GetAxis(PC2D.Input.VERTICAL) > 0;
            if (_motor.IsOnLadder())
            {
                if (
                    (up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Top)
                    ||
                    (!up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Bottom)
                    )
                {
                    // do nothing!
                }
                // if player hit up, while on the top do not enter in freeMode or a nasty short jump occurs
                else
                {
                    // example ladder behaviour

                    _motor.FreedomStateEnter();    // enter freedomState to disable gravity
                    _motor.EnableRestrictedArea(); // movements is retricted to a specific sprite bounds

                    // now disable OWP completely in a "trasactional way"
                    FreedomStateSave(_motor);
                    _motor.enableOneWayPlatforms   = false;
                    _motor.oneWayPlatformsAreWalls = false;

                    // start XY movement
                    _motor.normalizedXMovement = CrossPlatformInputManager.GetAxis(PC2D.Input.HORIZONTAL);
                    _motor.normalizedYMovement = CrossPlatformInputManager.GetAxis(PC2D.Input.VERTICAL);
                }
            }
        }
        else if (CrossPlatformInputManager.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD)
        {
            _motor.fallFast = false;
        }

        if (CrossPlatformInputManager.GetButtonDown(PC2D.Input.DASH))
        {
            _motor.Dash();

            GameObject.Find("AudioManager").GetComponent <AudioManager>().Play("Dash");
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        // use last state to restore some ladder specific values
        if (_motor.motorState != PlatformerMotor2D.MotorState.FreedomState)
        {
            // try to restore, sometimes states are a bit messy because change too much in one frame
            FreedomStateRestore(_motor);
        }

        // Jump?
        // If you want to jump in ladders, leave it here, otherwise move it down
        if (Input.GetButtonDown(PC2D.Input.JUMP))
        {
            _motor.Jump();
            _motor.DisableRestrictedArea();
        }

        _motor.jumpingHeld = Input.GetButton(PC2D.Input.JUMP);

        // XY freedom movement
        if (_motor.motorState == PlatformerMotor2D.MotorState.FreedomState)
        {
            _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL);
            _motor.normalizedYMovement = Input.GetAxis(PC2D.Input.VERTICAL);

            return; // do nothing more
        }

        // X axis movement
        if (Mathf.Abs(Input.GetAxis(PC2D.Input.HORIZONTAL)) > PC2D.Globals.INPUT_THRESHOLD)
        {
            _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL);
        }
        else
        {
            _motor.normalizedXMovement = 0;
        }

        if (Input.GetAxis(PC2D.Input.VERTICAL) != 0)
        {
            bool up_pressed = Input.GetAxis(PC2D.Input.VERTICAL) > 0;
            if (_motor.IsOnLadder())
            {
                if (
                    (up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Top)
                    ||
                    (!up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Bottom)
                    )
                {
                    // do nothing!
                }
                // if player hit up, while on the top do not enter in freeMode or a nasty short jump occurs
                else
                {
                    // example ladder behaviour

                    _motor.FreedomStateEnter();    // enter freedomState to disable gravity
                    _motor.EnableRestrictedArea(); // movements is retricted to a specific sprite bounds

                    // now disable OWP completely in a "trasactional way"
                    FreedomStateSave(_motor);
                    _motor.enableOneWayPlatforms   = false;
                    _motor.oneWayPlatformsAreWalls = false;

                    // start XY movement
                    _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL);
                    _motor.normalizedYMovement = Input.GetAxis(PC2D.Input.VERTICAL);
                }
            }
        }
        else if (Input.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD)
        {
            _motor.fallFast = false;
        }

        // 如果按下了 Shot 的 Input的話,
        if (Input.GetButtonDown(PC2D.Input.SHOT))
        {
            //把現在忍者的水平跟垂直按壓位移當作參數傳遞
            Vector2 pos = new Vector2(Input.GetAxis(PC2D.Input.HORIZONTAL), Input.GetAxis(PC2D.Input.VERTICAL));
            //發射手�媦C
            _shooter.Shot(pos);
        }

        if (Input.GetButtonDown(PC2D.Input.DASH))
        {
            _motor.Dash();
        }
    }
Пример #3
0
    void Update()
    {
        if (!_enableMove)
        {
            if (!_motor.frozen)
            {
                _motor.frozen = true;
            }
            return;
        }
        else
        {
            if (_motor.frozen)
            {
                _motor.frozen = false;
            }
        }

        // use last state to restore some ladder specific values
        if (_motor.motorState != PlatformerMotor2D.MotorState.FreedomState)
        {
            // try to restore, sometimes states are a bit messy because change too much in one frame
            FreedomStateRestore(_motor);
        }

        // Jump?
        // If you want to jump in ladders, leave it here, otherwise move it down
        if (Input.GetButtonDown(PC2D.Input.JUMP))
        {
            _motor.Jump();
            _motor.DisableRestrictedArea();

            if (_motor.IsOnLadder())
            {
                _motor.LadderAreaExit();
            }
        }

        _motor.jumpingHeld = Input.GetButton(PC2D.Input.JUMP);

        // XY freedom movement
        if (_motor.motorState == PlatformerMotor2D.MotorState.FreedomState)
        {
            _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL);
            _motor.normalizedYMovement = Input.GetAxis(PC2D.Input.VERTICAL);

            return; // do nothing more
        }

        // X axis movement
        if (Mathf.Abs(Input.GetAxis(PC2D.Input.HORIZONTAL)) > PC2D.Globals.INPUT_THRESHOLD)
        {
            _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL);
        }
        else
        {
            _motor.normalizedXMovement = 0;
        }

        if (Input.GetAxis(PC2D.Input.VERTICAL) != 0)
        {
            bool up_pressed = Input.GetAxis(PC2D.Input.VERTICAL) > 0;
            if (_motor.IsOnLadder())
            {
                if (
                    (up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Top)
                    ||
                    (!up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Bottom)
                    )
                {
                    // do nothing!
                }
                // if player hit up, while on the top do not enter in freeMode or a nasty short jump occurs
                else
                {
                    // example ladder behaviour

                    _motor.FreedomStateEnter();    // enter freedomState to disable gravity
                    _motor.EnableRestrictedArea(); // movements is retricted to a specific sprite bounds

                    // now disable OWP completely in a "trasactional way"
                    FreedomStateSave(_motor);
                    _motor.enableOneWayPlatforms   = false;
                    _motor.oneWayPlatformsAreWalls = false;

                    // start XY movement
                    _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL);
                    _motor.normalizedYMovement = Input.GetAxis(PC2D.Input.VERTICAL);
                }
            }
        }
        else if (Input.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD)
        {
            _motor.fallFast = false;
        }

        if (Input.GetKeyDown(PC2D.Input.START_SLIDE))
        {
            //m_Animator.SetTrigger("slide");
            m_Animator.Play("PlayerSlide");
            _motor.Dash();
        }

        if (Input.GetKeyDown(PC2D.Input.WAVE_SWORD))
        {
            _motor.Wave();
            if (_motor.motorState == PlatformerMotor2D.MotorState.JumpWave)
            {
                m_Animator.SetTrigger("jumpWave");
            }
            else
            {
                m_Animator.SetTrigger("wave");
            }
            meleeAttack.gameObject.SetActive(true);
        }

        if (Input.GetKeyUp(PC2D.Input.WAVE_SWORD))
        {
            meleeAttack.gameObject.SetActive(false);
            meleeAttack.DisableDamage();
        }

        if (Input.GetKeyDown(PC2D.Input.THROW_DAGGER))
        {
            _motor.Throw();
            if (_motor.motorState == PlatformerMotor2D.MotorState.JumpThrow)
            {
                m_Animator.SetTrigger("jumpThrow");
            }
            else
            {
                m_Animator.SetTrigger("throw");
            }
        }
    }
Пример #4
0
    private void UpdateWithController()
    {
        // use last state to restore some ladder specific values
        if (_motor.motorState != PlatformerMotor2D.MotorState.FreedomState)
        {
            // try to restore, sometimes states are a bit messy because change too much in one frame
            FreedomStateRestore(_motor);
        }

        //if (_motor.IsGrounded() && _motor.jumpHeight != defaultJumpHeight)
        //{
        //    _motor.jumpHeight = defaultJumpHeight;
        //}

        // Jump?
        // If you want to jump in ladders, leave it here, otherwise move it down
        if (InputManager.ActiveDevice.Action1.WasPressed)
        {
            if (hasNotMovedYet)
            {
                hasNotMovedYet   = false;
                isStartingToMove = true;
            }
        }

        if (_motor.normalizedXMovement == 0f && InputManager.ActiveDevice.Direction.Down.IsPressed)
        {
            isChargingJump = true;
        }

        if (InputManager.ActiveDevice.Direction.Down.WasReleased)
        {
            isChargingJump = false;
        }

        if (InputManager.ActiveDevice.Action1.WasPressed)
        {
            if (hasNotMovedYet)
            {
                hasNotMovedYet   = false;
                isStartingToMove = true;
            }
            if (InputManager.ActiveDevice.Direction.Down.IsPressed && !isCarryingItem)
            {
                _motor.jumpHeight = rechargedJumpHeight;
                _motor.Jump();
                _motor.DisableRestrictedArea();
                _motor.jumpHeight = defaultJumpHeight;
            }
            else
            {
                _motor.Jump();
                _motor.DisableRestrictedArea();
            }
            audioSource.PlayOneShot(jumpClip);
            timeChargingJump = 0f;
            isChargingJump   = false;
        }

        //_motor.jumpingHeld = Input.GetButton(PC2D.Input.JUMP);

        // XY freedom movement
        if (_motor.motorState == PlatformerMotor2D.MotorState.FreedomState)
        {
            _motor.normalizedXMovement = InputManager.ActiveDevice.Direction.X;
            _motor.normalizedYMovement = InputManager.ActiveDevice.Direction.Y;

            return; // do nothing more
        }

        // X axis movement
        if (Mathf.Abs(InputManager.ActiveDevice.Direction.X) > PC2D.Globals.INPUT_THRESHOLD)
        {
            if (hasNotMovedYet)
            {
                hasNotMovedYet   = false;
                isStartingToMove = true;
            }
            if (!isStartingToMove)
            {
                _motor.normalizedXMovement = InputManager.ActiveDevice.Direction.X;
                if (!audioSource.isPlaying && _motor.IsGrounded())
                {
                    audioSource.clip = walkClip;
                    audioSource.Play();
                }
            }
        }
        else
        {
            _motor.normalizedXMovement = 0;
        }

        if (InputManager.ActiveDevice.Direction.Y != 0)
        {
            if (hasNotMovedYet)
            {
                hasNotMovedYet   = false;
                isStartingToMove = true;
            }
            bool up_pressed = InputManager.ActiveDevice.Direction.Y > 0;
            if (_motor.IsOnLadder())
            {
                if (
                    (up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Top)
                    ||
                    (!up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Bottom)
                    )
                {
                    // do nothing!
                }
                // if player hit up, while on the top do not enter in freeMode or a nasty short jump occurs
                else
                {
                    // example ladder behaviour

                    _motor.FreedomStateEnter();    // enter freedomState to disable gravity
                    _motor.EnableRestrictedArea(); // movements is retricted to a specific sprite bounds

                    // now disable OWP completely in a "trasactional way"
                    FreedomStateSave(_motor);
                    _motor.enableOneWayPlatforms   = false;
                    _motor.oneWayPlatformsAreWalls = false;

                    // start XY movement
                    _motor.normalizedXMovement = InputManager.ActiveDevice.Direction.X;
                    _motor.normalizedYMovement = InputManager.ActiveDevice.Direction.Y;
                }
            }
        }
        else if (InputManager.ActiveDevice.Direction.Y < -PC2D.Globals.FAST_FALL_THRESHOLD)
        {
            if (hasNotMovedYet)
            {
                hasNotMovedYet   = false;
                isStartingToMove = true;
            }
            _motor.fallFast = false;
        }

        if (InputManager.ActiveDevice.Action2.WasPressed && !isCarryingItem)
        {
            _motor.Dash();
            if (hasNotMovedYet)
            {
                hasNotMovedYet   = false;
                isStartingToMove = true;
            }
        }

        if (InputManager.ActiveDevice.Action3.WasPressed && isInItem)
        {
            Carrying();
        }

        if (InputManager.ActiveDevice.Action3.WasReleased && isCarryingItem)
        {
            NotCarrying();
        }
    }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        // use last state to restore some ladder specific values
        if (_motor.motorState != PlatformerMotor2D.MotorState.FreedomState)
        {
            // try to restore, sometimes states are a bit messy because change too much in one frame
            FreedomStateRestore(_motor);
        }

        // Jump?
        // If you want to jump in ladders, leave it here, otherwise move it down
        if (haveJumped)         //Input.GetButtonDown(PC2D.Input.JUMP))
        {
            haveJumped = false;
            _motor.Jump();
            _motor.DisableRestrictedArea();
        }

        _motor.jumpingHeld = true;         // jumping; // Input.GetButton(PC2D.Input.JUMP);

        // XY freedom movement
        if (_motor.motorState == PlatformerMotor2D.MotorState.FreedomState)
        {
            _motor.normalizedXMovement = horizontal; //Input.GetAxis(PC2D.Input.HORIZONTAL);
            _motor.normalizedYMovement = vertical;   //Input.GetAxis(PC2D.Input.VERTICAL);

            return;                                  // do nothing more
        }

        // X axis movement
        if (Mathf.Abs(horizontal) > PC2D.Globals.INPUT_THRESHOLD)
        {
            _motor.normalizedXMovement = horizontal;             //Input.GetAxis(PC2D.Input.HORIZONTAL);
        }
        else
        {
            _motor.normalizedXMovement = 0;
        }

        // Y axis movement
        if (vertical != 0)                  //Input.GetAxis(PC2D.Input.VERTICAL) != 0)
        {
            bool up_pressed = vertical > 0; //Input.GetAxis(PC2D.Input.VERTICAL) > 0;
            if (_motor.IsOnLadder())
            {
                if (
                    (up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Top)
                    ||
                    (!up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Bottom)
                    )
                {
                    // do nothing!
                }
                // if player hit up, while on the top do not enter in freeMode or a nasty short jump occurs
                else
                {
                    // example ladder behaviour

                    _motor.FreedomStateEnter();                     // enter freedomState to disable gravity
                    _motor.EnableRestrictedArea();                  // movements is retricted to a specific sprite bounds

                    // now disable OWP completely in a "trasactional way"
                    FreedomStateSave(_motor);
                    _motor.enableOneWayPlatforms   = false;
                    _motor.oneWayPlatformsAreWalls = false;

                    // start XY movement
                    _motor.normalizedXMovement = horizontal;                   //Input.GetAxis(PC2D.Input.HORIZONTAL);
                    _motor.normalizedYMovement = vertical;                     //Input.GetAxis(PC2D.Input.VERTICAL);
                }
            }
        }
        else if (vertical < -PC2D.Globals.FAST_FALL_THRESHOLD)
        {
            _motor.fallFast = false;
        }

        if (dash)
        {
            dash = false;
            _motor.Dash();
        }

        if (attack)
        {
            attack = false;
            gameObject.GetComponent <PC2D.PlatformerAnimation2D>().Attack();
        }
    }
Пример #6
0
        // Update is called once per frame
        void Update()
        {
            //Debug.Log("cur state: " + _motor.motorState);
            if (_motor.motorState == PlatformerMotor2D.MotorState.OnGround)
            {
                _animator.SetBool("ground", true);
            }

            if (_motor.motorState == PlatformerMotor2D.MotorState.Jumping ||
                _isJumping &&
                (_motor.motorState == PlatformerMotor2D.MotorState.Falling ||
                 _motor.motorState == PlatformerMotor2D.MotorState.FallingFast))
            {
                _isJumping = true;
                _animator.Play("Jump");
                _animator.SetBool("ground", false);

                if (_motor.velocity.x <= -0.1f)
                {
                    _currentFacingLeft = true;
                }
                else if (_motor.velocity.x >= 0.1f)
                {
                    _currentFacingLeft = false;
                }

                Vector3 rotateDir = _currentFacingLeft ? Vector3.forward : Vector3.back;
                visualChild.transform.Rotate(rotateDir, jumpRotationSpeed * Time.deltaTime);
            }
            else
            {
                _isJumping = false;
                visualChild.transform.rotation = Quaternion.identity;

                if (_motor.motorState == PlatformerMotor2D.MotorState.Falling ||
                    _motor.motorState == PlatformerMotor2D.MotorState.FallingFast)
                {
                    //_animator.Play("Fall");
                }
                else if (_motor.motorState == PlatformerMotor2D.MotorState.WallSliding ||
                         _motor.motorState == PlatformerMotor2D.MotorState.WallSticking)
                {
                    //_animator.Play("Cling");
                }
                else if (_motor.motorState == PlatformerMotor2D.MotorState.OnCorner)
                {
                    //_animator.Play("On Corner");
                }
                else if (_motor.motorState == PlatformerMotor2D.MotorState.Slipping)
                {
                    //_animator.Play("Slip");
                }
                else if (_motor.motorState == PlatformerMotor2D.MotorState.Dashing)
                {
                    //_animator.Play("PlayerSlide");
                    //_animator.SetTrigger("slide");
                }
                else if (_motor.motorState == PlatformerMotor2D.MotorState.NormalWave)
                {
                    //_animator.SetTrigger("wave");
                }
                else if (_motor.motorState == PlatformerMotor2D.MotorState.JumpWave)
                {
                    //_animator.SetTrigger("jumpWave");
                    _motor.EndJumpAttack();
                }
                else if (_motor.motorState == PlatformerMotor2D.MotorState.NormalThrow)
                {
                    //_animator.SetTrigger("throw");
                    //_animator.Play("PlayerThrow");
                }
                else if (_motor.motorState == PlatformerMotor2D.MotorState.JumpThrow)
                {
                    //_animator.SetTrigger("jumpThrow");
                    //_animator.Play("PlayerJumpThrow");

                    _motor.EndJumpAttack();
                }
                else
                {
                    if (_motor.IsOnLadder())
                    {
                        _animator.SetBool("isOnLadder", true);
                    }
                    else
                    {
                        _animator.SetFloat("speed", _motor.velocity.sqrMagnitude);
                        _animator.SetBool("isOnLadder", false);
                    }

                    if (_motor.velocity.sqrMagnitude >= 0.1f * 0.1f)
                    {
                        _animator.Play("Walk");
                    }
                    else
                    {
                        _animator.Play("Idle");
                    }
                }
            }

            // Facing
            float valueCheck = _motor.normalizedXMovement;

            if (_motor.motorState == PlatformerMotor2D.MotorState.Slipping ||
                _motor.motorState == PlatformerMotor2D.MotorState.Dashing ||
                _motor.motorState == PlatformerMotor2D.MotorState.Jumping)
            {
                valueCheck = _motor.velocity.x;
            }

            if (Mathf.Abs(valueCheck) >= 0.1f)
            {
                Vector3 newScale = visualChild.transform.localScale;
                newScale.x = Mathf.Abs(newScale.x) * ((valueCheck > 0) ? 1.0f : -1.0f);
                visualChild.transform.localScale = newScale;
            }
        }