Beispiel #1
0
 public GamepadInfo()
 {
     //for (int i = 0; i < 2; i++)
     //{
     //    stick[i] = new Stick();
     //    stick[i].num_axis = 2;
     //    stick[i].axis = new Stick.Axis[2];
     //    for (int j = 0; j < 1; j++)
     //        stick[i].axis[j] = new Stick.Axis();
     //    stick[i].axis[0].name = "UpDown";
     //    stick[i].axis[1].name = "LeftRight";
     //}
     stick[0] = new Stick();
     stick[0].name = "DPad";
     stick[0].num_axis = 4;
     stick[0].axis = new Stick.Axis[4];
     stick[0].axis[0].name = "Left Right";
     stick[0].axis[1].name = "Up Down";
     stick[0].axis[2].name = "LeftUp RightDown";
     stick[0].axis[3].name = "LeftDown RightUp";
     //stick[2].axis[4].name = "Down";
     //stick[2].axis[5].name = "DownLeft";
     //stick[2].axis[6].name = "Left";
     //stick[2].axis[7].name = "LeftUp";
     for (int i = 0; i < 10; i++) button = new Button[10];
     button[0].name = "A button";
     button[1].name = "Y button";
     button[2].name = "X button";
     button[3].name = "B button";
     button[4].name = "Back button";
     button[5].name = "Start button";
     button[6].name = "ShoulderLeft button";
     button[7].name = "ShoulderRight button";
     button[8].name = "LeftStick button";
     button[9].name = "RightStick button";
     //stick[0].name = "Left analog stick";
     //stick[1].name = "Right analog stick";
 }
        /// <summary>
        /// Checks if a thumbstick was quickly tapped in a certain direction. 
        /// This is useful for navigating menus and other situations where
        /// we treat a thumbstick as a D-Pad.
        /// </summary>
        /// <param name="which">Which stick to check: left or right</param>
        /// <param name="direction">A vector in the direction to check. 
        /// The length, which should be between 0.0 and 1.0, determines how
        /// far the stick must be rocked to "count"</param>
        /// <returns></returns>
        public bool WasStickTwitched(Stick which, Vector2 direction)
        {
            if (direction.X == 0 && direction.Y == 0)
                return false;

            Vector2 stickOld, stickNew;
            if (which == Stick.Left)
            {
                stickOld = oldState.ThumbSticks.Left;
                stickNew = newState.ThumbSticks.Left;
            }
            else
            {
                stickOld = oldState.ThumbSticks.Right;
                stickNew = newState.ThumbSticks.Right;
            }

            Vector2 twitch = stickNew;
            bool x = (direction.X == 0 || twitch.X / direction.X > 1);
            bool y = (direction.Y == 0 || twitch.Y / direction.Y > 1);
            bool twitchNew = x && y;

            twitch = stickOld;
            x      = (direction.X == 0 || twitch.X / direction.X > 1);
            y      = (direction.Y == 0 || twitch.Y / direction.Y > 1);
            bool twitchOld = x && y;

            return twitchNew && !twitchOld;
        }
Beispiel #3
0
        /// <summary>
        /// Check if a stick on the gamepad is not pressed down in a particular direction, similar to the DPad directional buttons
        /// </summary>
        /// <param name="dir">Direction of the stick we are checking</param>
        /// <param name="playerNum">Player to be checked</param>
        /// <returns>Return of the stick is not pressed in thats direction or not</returns>
        public static bool IsStickUp(Stick stick, Direction dir, PlayerIndex playerNum)
        {
            //1. Get the stick in question
            Vector2 stickPos;
            if (stick == Stick.Left)
                stickPos = currentGamepadState[(int)playerNum].ThumbSticks.Left;
            else
                stickPos = currentGamepadState[(int)playerNum].ThumbSticks.Right;

            //2. Run the IsStickUp check
            switch (dir)
            {
                case Direction.Up:
                    return (stickPos.Y < 0.5);
                case Direction.Left:
                    return (stickPos.X > -0.5);
                case Direction.Down:
                    return (stickPos.Y > -0.5);
                case Direction.Right:
                    return (stickPos.X < 0.5);
                default:
                    throw new ArgumentOutOfRangeException("Direction inputted is not a viable direction.");
            }
        }
Beispiel #4
0
 /// <summary>
 /// Get the current position of a joystick on the gamepad for a certain player
 /// </summary>
 /// <param name="stick">Stick to check</param>
 /// <param name="playerNum">Player to be checked</param>
 /// <returns>Current position of the joystick inputted</returns>
 public static Vector2 GetStickPosition(Stick stick, PlayerIndex playerNum)
 {
     if (stick == Stick.Left)
         return currentGamepadState[(int)playerNum].ThumbSticks.Left;
     else
         return currentGamepadState[(int)playerNum].ThumbSticks.Right;
 }
Beispiel #5
0
        /// <summary>
        /// Check if a stick on the gamepad is released in a particular direction, similar to the DPad directional buttons
        /// (Currently unpressed but pressed last update)
        /// </summary>
        /// <param name="dir">Direction of the stick we are checking</param>
        /// <param name="playerNum">Player to be checked</param>
        /// <returns>Return of the stick is released in thats direction or not</returns>
        public static bool IsStickReleased(Stick stick, Direction dir, PlayerIndex playerNum)
        {
            //1. Get the sticks in question
            Vector2 currentStickPos, prevStickPos;
            if (stick == Stick.Left)
            {
                currentStickPos = currentGamepadState[(int)playerNum].ThumbSticks.Left;
                prevStickPos = prevGamepadState[(int)playerNum].ThumbSticks.Left;
            }
            else
            {
                currentStickPos = currentGamepadState[(int)playerNum].ThumbSticks.Right;
                prevStickPos = prevGamepadState[(int)playerNum].ThumbSticks.Right;
            }

            //2. Run the IsStickPressed check
            switch (dir)
            {
                case Direction.Up:
                    return (currentStickPos.Y < 0.5) && (prevStickPos.Y >= 0.5);
                case Direction.Left:
                    return (currentStickPos.X > -0.5) && (prevStickPos.X <= -0.5);
                case Direction.Down:
                    return (currentStickPos.Y > -0.5) && (prevStickPos.Y <= -0.5);
                case Direction.Right:
                    return (currentStickPos.X < 0.5) && (prevStickPos.X >= 0.5);
                default:
                    throw new ArgumentOutOfRangeException("Direction inputted is not a viable direction.");
            }
        }