示例#1
0
        public void DoAction(PlatformerMotor2D motor, TriggerAction action, bool exitFreeMode)
        {
            switch (action)
            {
            case TriggerAction.EnableRestrictedAreaIfFreemode:
                if (motor.motorState == PlatformerMotor2D.MotorState.FreedomState)
                {
                    motor.EnableRestrictedArea();
                }
                break;

            case TriggerAction.EnableRestrictedArea:
                motor.EnableRestrictedArea();
                break;

            case TriggerAction.DisableRestrictedAreaIfFreemode:
                if (motor.motorState == PlatformerMotor2D.MotorState.FreedomState)
                {
                    motor.DisableRestrictedArea();
                }
                break;

            case TriggerAction.DisableRestrictedArea:
                motor.DisableRestrictedArea();
                break;
            }

            if (exitFreeMode)
            {
                if (motor.motorState == PlatformerMotor2D.MotorState.FreedomState)
                {
                    motor.FreedomStateExit();
                }
            }
        }
示例#2
0
        public void DoAction(PlatformerMotor2D motor, TriggerAction action, bool exitFreeMode)
        {
            switch(action) {
            case TriggerAction.EnableRestrictedAreaIfFreemode:
                if (motor.motorState == PlatformerMotor2D.MotorState.FreedomState) {
                    motor.EnableRestrictedArea();
                }
                break;
            case TriggerAction.EnableRestrictedArea:
                motor.EnableRestrictedArea();
                break;
            case TriggerAction.DisableRestrictedAreaIfFreemode:
                if (motor.motorState == PlatformerMotor2D.MotorState.FreedomState) {
                    motor.DisableRestrictedArea();
                }
                break;
            case TriggerAction.DisableRestrictedArea:
                motor.DisableRestrictedArea();
                break;
            }

            if (exitFreeMode)
            {
                if (motor.motorState == PlatformerMotor2D.MotorState.FreedomState)
                {
                    motor.FreedomStateExit();
                }
            }
        }
示例#3
0
 public void Jump(bool down)
 {
     if (down)
     {
         _motor.Jump();
         _motor.DisableRestrictedArea();
     }
     _motor.jumpingHeld = down;
 }
示例#4
0
        public override void OnTriggerExit2D(Collider2D o)
        {
            base.OnTriggerExit2D(o);

            PlatformerMotor2D motor = o.GetComponent <PlatformerMotor2D>();

            if (motor)
            {
                motor.FreedomAreaExit();
                if (enableRestrictedArea)
                {
                    motor.DisableRestrictedArea();
                    motor.ClearRestrictedArea();
                }
            }
        }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        // 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);

        // 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 (Input.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD)
            {
                _motor.fallFast = false;
            }
        }

        if (Input.GetAxisRaw(PC2D.Input.VERTICAL) == -1)
        {
            _motor.Drop();
        }
        else if (Input.GetButtonDown(PC2D.Input.DASH))
        {
            _motor.Dash();
        }
        else if (Input.GetButtonDown(PC2D.Input.SLASH))
        {
            _motor.Slash();
        }
    }
示例#6
0
    void Update()
    {
        // ゴールフラグが true になると sceneState が99になる
        if (goal.isGoal() == true)
        {
            sceneState = 99;
            BgmManager.Instance.Stop();

            // キャプションを表示
            Camption.gameObject.SetActive(true);

            player.IsSkipJumpSe = true;
            playerPlatformerMotor2D.Jump();
            playerPlatformerMotor2D.DisableRestrictedArea();
        }

        // シーンステートが99の時、任意のキーで次のシーンへ
        if (sceneState == 99 && Input.GetKeyDown(keyCode))
        {
            //Debug.Log("LoadScene");
            // フェード時間を設定してシーン遷移
            FadeManager.Instance.LoadScene(nextScene, fadeTime);
        }
    }
示例#7
0
 public void Jump()
 {
     _motor.Jump();
     _motor.DisableRestrictedArea();
     _motor.jumpingHeld = true;
 }
示例#8
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");
        }
    }
示例#9
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();
        }
    }
示例#10
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");
            }
        }
    }
示例#11
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();
        }
    }
示例#12
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();
        }
    }