public static GlobalGameConstants.Direction PlayerAnalogStickDirection(PPG_Player player) { if (bindings[(int)player] == PlayerPad.Keyboard) { return(GlobalGameConstants.Direction.NoDirection); } else if ((int)bindings[(int)player] > -1) { GamePadState state = xInputControllers[(int)bindings[(int)player]]; // some third-party gamepads don't help with this if (float.IsNaN(state.ThumbSticks.Left.X) || float.IsNaN(state.ThumbSticks.Left.Y)) { return(GlobalGameConstants.Direction.NoDirection); } if (state.ThumbSticks.Left.Length() < 0.05f) { return(GlobalGameConstants.Direction.NoDirection); } if (Math.Abs(state.ThumbSticks.Left.X) > Math.Abs(state.ThumbSticks.Left.Y)) { if (state.ThumbSticks.Left.X < 0) { return(GlobalGameConstants.Direction.Left); } else { return(GlobalGameConstants.Direction.Right); } } else { if (state.ThumbSticks.Left.Y < 0) { return(GlobalGameConstants.Direction.Down); } else { return(GlobalGameConstants.Direction.Up); } } } return(GlobalGameConstants.Direction.NoDirection); }
/// <summary> /// Returns the GamePad index for system calls. /// </summary> /// <param name="player">Player requested.</param> /// <returns>PlayerIndex for specified player. Throws an exception for unindexed pads and the Keyboard.</returns> public static PlayerIndex GetPlayerGamePadIndex(PPG_Player player) { switch (bindings[(int)player]) { case PlayerPad.GamePad1: case PlayerPad.GamePad2: case PlayerPad.GamePad3: case PlayerPad.GamePad4: return((PlayerIndex)bindings[(int)player]); break; case PlayerPad.Keyboard: case PlayerPad.NoPad: default: throw new InvalidOperationException("No Xbox Gamepad index for " + bindings[(int)player].ToString()); } }
/// <summary> /// If a player is assigned to a certain input device, its assignment is removed. Otherwise does nothing. /// </summary> /// <param name="player">The player to unassign.</param> public static void UnlockController(PPG_Player player) { bindings[(int)player] = PlayerPad.NoPad; }
/// <summary> /// Checks if a button is pressed for a specified Player. /// </summary> /// <param name="player">The assigned player index to check.</param> /// <param name="button">The button to poll.</param> /// <returns>True if the button for the player's device is pressed.</returns> public static bool IsPlayerButtonDown(PPG_Player player, PlayerButton button) { if (bindings[(int)player] == PlayerPad.Keyboard) { switch (button) { case PlayerButton.Confirm: if (keyboardController.IsKeyDown(keyConfig.Confirm)) { return(true); } break; case PlayerButton.Cancel: if (keyboardController.IsKeyDown(keyConfig.Cancel)) { return(true); } break; case PlayerButton.PauseButton: if (keyboardController.IsKeyDown(keyConfig.PauseButton)) { return(true); } break; case PlayerButton.BackButton: if (keyboardController.IsKeyDown(keyConfig.BackButton)) { return(true); } break; case PlayerButton.UseItem2: if (keyboardController.IsKeyDown(keyConfig.UseLeftItem)) { return(true); } break; case PlayerButton.UseItem1: if (keyboardController.IsKeyDown(keyConfig.UseRightItem)) { return(true); } break; case PlayerButton.SwitchItem1: if (keyboardController.IsKeyDown(keyConfig.SwitchItem1)) { return(true); } break; case PlayerButton.SwitchItem2: if (keyboardController.IsKeyDown(keyConfig.SwitchItem2)) { return(true); } break; case PlayerButton.DownDirection: if (keyboardController.IsKeyDown(keyConfig.DownDirection)) { return(true); } break; case PlayerButton.UpDirection: if (keyboardController.IsKeyDown(keyConfig.UpDirection)) { return(true); } break; case PlayerButton.LeftDirection: if (keyboardController.IsKeyDown(keyConfig.LeftDirection)) { return(true); } break; case PlayerButton.RightDirection: if (keyboardController.IsKeyDown(keyConfig.RightDirection)) { return(true); } break; } } else if ((int)bindings[(int)player] > -1) { GamePadState state = xInputControllers[(int)bindings[(int)player]]; switch (button) { case PlayerButton.Confirm: if (state.Buttons.A == ButtonState.Pressed) { return(true); } break; case PlayerButton.Cancel: if (state.Buttons.B == ButtonState.Pressed) { return(true); } break; case PlayerButton.PauseButton: if (state.Buttons.Start == ButtonState.Pressed) { return(true); } break; case PlayerButton.BackButton: if (state.Buttons.Back == ButtonState.Pressed) { return(true); } break; case PlayerButton.UseItem2: if (state.Buttons.A == ButtonState.Pressed || state.Triggers.Left > 0.01f) { return(true); } break; case PlayerButton.UseItem1: if (state.Buttons.B == ButtonState.Pressed || state.Triggers.Right > 0.01f) { return(true); } break; case PlayerButton.SwitchItem1: if (state.Buttons.X == ButtonState.Pressed || state.Buttons.RightShoulder == ButtonState.Pressed) { return(true); } break; case PlayerButton.SwitchItem2: if (state.Buttons.Y == ButtonState.Pressed || state.Buttons.LeftShoulder == ButtonState.Pressed) { return(true); } break; case PlayerButton.DownDirection: if (state.DPad.Down == ButtonState.Pressed || state.ThumbSticks.Left.Y < 0) { return(true); } break; case PlayerButton.UpDirection: if (state.DPad.Up == ButtonState.Pressed || state.ThumbSticks.Left.Y > 0) { return(true); } break; case PlayerButton.LeftDirection: if (state.DPad.Left == ButtonState.Pressed || state.ThumbSticks.Left.X < 0) { return(true); } break; case PlayerButton.RightDirection: if (state.DPad.Right == ButtonState.Pressed || state.ThumbSticks.Left.X > 0) { return(true); } break; } } return(false); }
/// <summary> /// Assigns a specified player to a certain pad. /// </summary> /// <param name="player">The player to assign to a device.</param> /// <param name="pad">The input device to be assigned a player.</param> /// <remarks>Allows the programmer to check input on a device without knowing what it's type/index is.</remarks> public static void LockController(PPG_Player player, PlayerPad pad) { bindings[(int)player] = pad; }