Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (!_manager.isPaused)
        {
            _motor.frozen  = false;
            _motor.enabled = true;
            // Input based off of an xbox one controller
            //Check for the pressing of the button
            //and if character is jumping already

            if (Input.GetKey(KeyCode.Joystick1Button0) && !_motor.IsInAir())
            {
                //Make the player jump duh?
                _motor.Jump();
            }

            //Move player based off left joystick input
            _motor.normalizedXMovement = Input.GetAxis("Axis 1") * speed;
        }
        else
        {
            _motor.frozen  = true;
            _motor.enabled = false;
        }
    }
Пример #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(JUMP))
            {
                _motor.Jump();
                _motor.DisableRestrictedArea();
            }

            _motor.jumpingHeld = Input.GetButton(JUMP);

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

                return;     // do nothing more
            }

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

            if (Input.GetAxis(VERTICAL) != 0)
            {
                bool up_pressed = Input.GetAxis(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(HORIZONTAL);
                        _motor.normalizedYMovement = Input.GetAxis(VERTICAL);
                    }
                }
            }
            else if (Input.GetAxis(VERTICAL) < -FAST_FALL_THRESHOLD)
            {
                _motor.fallFast = false;
            }

            if (Input.GetButtonDown(DASH) && _motor.IsInAir())
            {
                _motor.Dash();
            }
        }