Ejemplo n.º 1
0
    /*
     * Handle toggling of targetting as well as switching between targets. While holding down
     * target button, player can cycle through targets.
     */
    void TryTargetting()
    {
        float       deadStickThreshold = 0.5f;
        InputDevice xbox = InputDevices.GetAllInputDevices() [(int)InputDevices.ControllerTypes.XBox];
        float       rightStickPressedAxis = Input.GetAxisRaw(RBInput.ConcatPlayerIndex(InputStrings.TARGET, PlayerIndex, xbox));
        bool        rightStickPressed     = rightStickPressedAxis >= 0.99 && rightStickAvailable;
        // Consolidate bool for PC and XBox
        bool isTargetPressed = RBInput.GetButtonDownForPlayer(InputStrings.TARGET, PlayerIndex) ||
                               rightStickPressed;

        // Toggle Targeting on and off
        if (isTargetPressed)
        {
            rightStickAvailable = false;
            if (!fighter.isLockedOn)
            {
                TargetNearest();
            }
            else
            {
                fighter.LoseTarget();
            }
        }

        // Switch between targets
        if (fighter.isLockedOn)
        {
            // PC and Controller controls likely should diverge here due to right stick use
            InputDevice pc = InputDevices.GetAllInputDevices() [(int)InputDevices.ControllerTypes.Keyboard];
            float       horizontalTargetAxis = Input.GetAxisRaw(RBInput.ConcatPlayerIndex(InputStrings.TARGETHORIZONTAL, PlayerIndex, xbox));
            float       verticalTargetAxis   = -Input.GetAxisRaw(RBInput.ConcatPlayerIndex(InputStrings.TARGETVERTCIAL, PlayerIndex, xbox));

            // Move target in axis direction
            bool  changingTarget = false;
            float horizontal     = 0;
            float vertical       = 0;

            //
            // Read in PC input
            //
            // Set Horizontal Input for PC
            if (Input.GetButtonDown(RBInput.ConcatPlayerIndex(InputStrings.TARGETLEFT, PlayerIndex, pc)))
            {
                //|| )) {
                //rightStickHorizontalAvailable = false;
                //TargetNext (true);
                horizontal     = -1;
                changingTarget = true;
            }
            else if (Input.GetButtonDown(RBInput.ConcatPlayerIndex(InputStrings.TARGETRIGHT, PlayerIndex, pc)))
            {
                horizontal     = 1;
                changingTarget = true;
            }
            // Set Vertical Input
            if (Input.GetButtonDown(RBInput.ConcatPlayerIndex(InputStrings.TARGETDOWN, PlayerIndex, pc)))
            {
                vertical       = -1;
                changingTarget = true;
            }
            else if (Input.GetButtonDown(RBInput.ConcatPlayerIndex(InputStrings.TARGETUP, PlayerIndex, pc)))
            {
                vertical       = 1;
                changingTarget = true;
            }

            //
            // Read in XBox input
            //
            // Set Horizontal and Vertical values for XBox
            bool horizontalAxisPressed = rightStickAxisAvailable &&
                                         (horizontalTargetAxis <-deadStickThreshold || horizontalTargetAxis> deadStickThreshold);
            bool verticalAxisPressed = rightStickAxisAvailable &&
                                       (verticalTargetAxis <-deadStickThreshold || verticalTargetAxis> deadStickThreshold);
            if (horizontalAxisPressed || verticalAxisPressed)
            {
                rightStickAxisAvailable = false;
                TargetNearDirection(horizontalTargetAxis, verticalTargetAxis);
                changingTarget = true;
            }

            // Make target change
            if (changingTarget)
            {
                TargetNearDirection(horizontal, vertical);
            }

            // Enforce stick behavior like a button
            rightStickAxisAvailable = IsAxisDead(horizontalTargetAxis, deadStickThreshold) &&
                                      IsAxisDead(verticalTargetAxis, deadStickThreshold);
        }
        rightStickAvailable = IsAxisDead(rightStickPressedAxis, deadStickThreshold);
    }