Пример #1
0
        /// <summary>
        /// Returns state of the specified button on the InputFrom
        /// </summary>
        /// <param name="form">Input form to check against</param>
        /// <param name="bttnID">ID of what button to check</param>
        /// <returns></returns>
        private static buttonState GetButtonState(InputForm form, GenericButtonID bttnID) {

            // Bitwise operation to see if it has the button (means it is/was pressed)
            if ((form.m_button & bttnID) != 0) { return buttonState.PRESSED; }

            return buttonState.RELEASED;
        }
Пример #2
0
        /// <summary>
        /// Returns state of the specified button on the InputFrom
        /// </summary>
        /// <param name="form">Input form to check against</param>
        /// <param name="bttnID">ID of what button to check</param>
        /// <returns></returns>
        private static buttonState GetButtonState(InputForm form, GenericButtonID bttnID)
        {
            // Bitwise operation to see if it has the button (means it is/was pressed)
            if ((form.m_button & bttnID) != 0)
            {
                return(buttonState.PRESSED);
            }

            return(buttonState.RELEASED);
        }
Пример #3
0
        public InputForm GetInputState(GamepadMapping plyrSetup) {

            InputForm rtnForm = new InputForm();

            GamePadState gmpdState = GamePad.GetState((PlayerIndex)(plyrSetup.gmpdID), GamePadDeadZone.IndependentAxes);

            UpdateButtonStates(ref rtnForm, gmpdState, plyrSetup.m_buttonCodes);
            UpdateAxisStates(ref rtnForm, gmpdState, plyrSetup.m_axisCodes);
            return rtnForm;
        }
Пример #4
0
        public InputForm GetInputState(GamepadMapping plyrSetup)
        {
            InputForm rtnForm = new InputForm();

            GamePadState gmpdState = GamePad.GetState((PlayerIndex)(plyrSetup.gmpdID), GamePadDeadZone.IndependentAxes);

            UpdateButtonStates(ref rtnForm, gmpdState, plyrSetup.m_buttonCodes);
            UpdateAxisStates(ref rtnForm, gmpdState, plyrSetup.m_axisCodes);
            return(rtnForm);
        }
Пример #5
0
        /// <summary>
        /// Returns state of the specified axis on the InputFrom
        /// </summary>
        /// <param name="form">Input form to check against</param>
        /// <param name="axsID">ID of what axis to check</param>
        /// <returns></returns>
        private static float GetAxisState(InputForm form, GenericAxisID axsID)
        {
            float rtrnVal = 0f;

            if (form.m_axis.Length > 0 && (int)axsID <= form.m_axis.Length && axsID != GenericAxisID.NONE)
            {
                rtrnVal = form.m_axis[(int)axsID - 1];
            }

            return(rtrnVal);
        }
Пример #6
0
        /// <summary>
        /// Returns the state of a specified button on a specified controller
        /// </summary>
        /// <param name="bttnInpt">ID of button to check against</param>
        /// <param name="plyrID">ID of corresponding player to check against</param>
        /// <returns></returns>
        public static bool GetButton(AbstractButtonInput bttnInpt, PlayerID plyrID = PlayerID.FIRST)
        {
            InputForm curInForm = GetCurrentState(plyrID);          // Current Input form

            if (GetButtonState(curInForm, AbstractToButtonID(bttnInpt)) == buttonState.PRESSED)
            {
                return(true);
            }

            return(false);
        }
Пример #7
0
        private void UpdateAxisStates(ref InputForm inptForm, GamePadState gmpdState, GmpdAxis[] axsCodes) {
            inptForm.m_axis = new float[axsCodes.Length];

            // Get axises
            for (int j = 0; j < axsCodes.Length; j++) {
                if(IsDPad(axsCodes[j])) {
                    inptForm.m_axis[j] = InputGetDPadAxisState(gmpdState.DPad, axsCodes[j]);
                } else {
                    inptForm.m_axis[j] = InputGetAxisState(ref gmpdState, axsCodes[j]);
                }
            }
        }
Пример #8
0
        private void UpdateButtonStates(ref InputForm inptForm, GamePadState gmpdState, GmpdButton[] bttnCodes) {

            // Get buttons
            for (int i = 0; i < bttnCodes.Length; i++) {
                if (IsDPad(bttnCodes[i])) {
                    if (InputGetDPadButtonState(gmpdState.DPad, bttnCodes[i]))
                        inptForm.m_button |= (GenericButtonID)((int)1 << i);
                } else {
                    if (InputGetButtonState(gmpdState.Buttons, bttnCodes[i]))
                        inptForm.m_button |= (GenericButtonID)((int)1 << i);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Returns true during the frame the user releases the button
        /// </summary>
        /// <param name="bttnInpt">ID of button to check against</param>
        /// <param name="plyrID">ID of corresponding player to check against</param>
        /// <returns></returns>
        public static bool GetButtonUp(AbstractButtonInput bttnInpt, PlayerID plyrID = PlayerID.FIRST)
        {
            InputForm curInForm  = GetCurrentState(plyrID);
            InputForm prevInForm = GetPreviousState(plyrID);

            if ((GetButtonState(curInForm, AbstractToButtonID(bttnInpt)) == buttonState.RELEASED) &&
                (GetButtonState(prevInForm, AbstractToButtonID(bttnInpt)) == buttonState.PRESSED))
            {
                return(true);
            }

            return(false);
        }
Пример #10
0
        private void UpdateAxisStates(ref InputForm inptForm, GamePadState gmpdState, GmpdAxis[] axsCodes)
        {
            inptForm.m_axis = new float[axsCodes.Length];

            // Get axises
            for (int j = 0; j < axsCodes.Length; j++)
            {
                if (IsDPad(axsCodes[j]))
                {
                    inptForm.m_axis[j] = InputGetDPadAxisState(gmpdState.DPad, axsCodes[j]);
                }
                else
                {
                    inptForm.m_axis[j] = InputGetAxisState(ref gmpdState, axsCodes[j]);
                }
            }
        }
Пример #11
0
        public InputForm GetInputState(KeyboardMapping plyrKybrdSttngs) {
            InputForm rtnForm = new InputForm();

            KeyCode[] kyCodes = plyrKybrdSttngs.m_keyCodes;

            // Get buttons 
            for (int i = 0; i < kyCodes.Length; i++) {
                if (GetButtonStates(kyCodes[i])) {
                    rtnForm.m_button |= (GenericButtonID)((int)1 << i);
                }
            }

            rtnForm.m_axis = new float[plyrKybrdSttngs.m_keyToAxis.Length];
            // Get axis
            for (int j = 0; j < plyrKybrdSttngs.m_keyToAxis.Length; j++) {
                rtnForm.m_axis[j] = GetAxisStates(plyrKybrdSttngs.m_keyToAxis[j]);
            }

            return rtnForm;
        }
Пример #12
0
        private static void UpdateInputForm(int plyrNum)
        {
            previousInputFormStates[plyrNum] = currentInputFormStates[plyrNum];

            // Depending on what type of input a player is assigned (keyboard, Gamepad)
            switch (playerInputSetup[plyrNum].type)
            {
            case InputDevice.GAMEPAD:
                currentInputFormStates[plyrNum] = gmpdInput.GetInputState((GamepadMapping)playerInputSetup[plyrNum]);
                break;

            case InputDevice.KEYBOARD:
                currentInputFormStates[plyrNum] = kybrdInput.GetInputState((KeyboardMapping)playerInputSetup[plyrNum]);
                break;

            default:
                currentInputFormStates[plyrNum] = new InputForm();
                break;
            }
        }
Пример #13
0
 private void UpdateButtonStates(ref InputForm inptForm, GamePadState gmpdState, GmpdButton[] bttnCodes)
 {
     // Get buttons
     for (int i = 0; i < bttnCodes.Length; i++)
     {
         if (IsDPad(bttnCodes[i]))
         {
             if (InputGetDPadButtonState(gmpdState.DPad, bttnCodes[i]))
             {
                 inptForm.m_button |= (GenericButtonID)((int)1 << i);
             }
         }
         else
         {
             if (InputGetButtonState(gmpdState.Buttons, bttnCodes[i]))
             {
                 inptForm.m_button |= (GenericButtonID)((int)1 << i);
             }
         }
     }
 }
Пример #14
0
        public InputForm GetInputState(KeyboardMapping plyrKybrdSttngs)
        {
            InputForm rtnForm = new InputForm();

            KeyCode[] kyCodes = plyrKybrdSttngs.m_keyCodes;

            // Get buttons
            for (int i = 0; i < kyCodes.Length; i++)
            {
                if (GetButtonStates(kyCodes[i]))
                {
                    rtnForm.m_button |= (GenericButtonID)((int)1 << i);
                }
            }

            rtnForm.m_axis = new float[plyrKybrdSttngs.m_keyToAxis.Length];
            // Get axis
            for (int j = 0; j < plyrKybrdSttngs.m_keyToAxis.Length; j++)
            {
                rtnForm.m_axis[j] = GetAxisStates(plyrKybrdSttngs.m_keyToAxis[j]);
            }

            return(rtnForm);
        }
Пример #15
0
        /// <summary>
        /// Returns the value of the axis identified
        /// </summary>
        /// <param name="axisInpt">ID of axis to check against</param>
        /// <param name="plyrID">ID of corresponding player to check against</param>
        /// <returns></returns>
        public static float GetAxis(AbstractAxisInput axisInpt, PlayerID plyrID = PlayerID.FIRST)
        {
            InputForm curInForm = GetCurrentState(plyrID);

            return(GetAxisState(curInForm, AbstractToAxisID(axisInpt)));
        }
Пример #16
0
        private static void UpdateInputForm(int plyrNum) {
            previousInputFormStates[plyrNum] = currentInputFormStates[plyrNum];

            // Depending on what type of input a player is assigned (keyboard, Gamepad)
            switch (playerInputSetup[plyrNum].type) {
                case InputDevice.GAMEPAD:
                    currentInputFormStates[plyrNum] = gmpdInput.GetInputState((GamepadMapping)playerInputSetup[plyrNum]);
                    break;
                case InputDevice.KEYBOARD:
                    currentInputFormStates[plyrNum] = kybrdInput.GetInputState((KeyboardMapping)playerInputSetup[plyrNum]);
                    break;
                default:
                    currentInputFormStates[plyrNum] = new InputForm();
                    break;
            }
        }
Пример #17
0
        /// <summary>
        /// Returns state of the specified axis on the InputFrom
        /// </summary>
        /// <param name="form">Input form to check against</param>
        /// <param name="axsID">ID of what axis to check</param>
        /// <returns></returns>
        private static float GetAxisState(InputForm form, GenericAxisID axsID) {
            float rtrnVal = 0f;

            if (form.m_axis.Length > 0 && (int)axsID <= form.m_axis.Length && axsID != GenericAxisID.NONE) {
                rtrnVal = form.m_axis[(int)axsID - 1];
            }

            return rtrnVal;
        }