Guest User

Untitled

a guest
May 10th, 2012
30
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.        /// <summary>
  2.         /// Helper for checking if a key was newly pressed during this update. The
  3.         /// controllingPlayer parameter specifies which player to read input for.
  4.         /// If this is null, it will accept input from any player. When a keypress
  5.         /// is detected, the output playerIndex reports which player pressed it.
  6.         /// </summary>
  7.         public bool IsNewKeyPress(Keys key, PlayerIndex? controllingPlayer,
  8.                                             out PlayerIndex playerIndex)
  9.         {
  10.             if (controllingPlayer.HasValue)
  11.             {
  12.                 // Read input from the specified player.
  13.                 playerIndex = controllingPlayer.Value;
  14.  
  15.                 int i = (int)playerIndex;
  16.  
  17.                 return (CurrentKeyboardState[i].IsKeyDown(key) &&
  18.                         LastKeyboardState[i].IsKeyUp(key));
  19.             }
  20.             else
  21.             {
  22.                 // Accept input from any player.
  23.                 return (IsNewKeyPress(key, PlayerIndex.One, out playerIndex) ||
  24.                         IsNewKeyPress(key, PlayerIndex.Two, out playerIndex) ||
  25.                         IsNewKeyPress(key, PlayerIndex.Three, out playerIndex) ||
  26.                         IsNewKeyPress(key, PlayerIndex.Four, out playerIndex));
  27.             }
  28.         }
  29.  
  30.         /// <summary>
  31.         /// Helper for checking if a button was newly pressed during this update.
  32.         /// The controllingPlayer parameter specifies which player to read input for.
  33.         /// If this is null, it will accept input from any player. When a button press
  34.         /// is detected, the output playerIndex reports which player pressed it.
  35.         /// </summary>
  36.         public bool IsNewButtonPress(Buttons button, PlayerIndex? controllingPlayer,
  37.                                                      out PlayerIndex playerIndex)
  38.         {
  39.             if (controllingPlayer.HasValue)
  40.             {
  41.                 // Read input from the specified player.
  42.                 playerIndex = controllingPlayer.Value;
  43.  
  44.                 int i = (int)playerIndex;
  45.  
  46.                 return (CurrentGamePadState[i].IsButtonDown(button) &&
  47.                         LastGamePadState[i].IsButtonUp(button));
  48.             }
  49.             else
  50.             {
  51.                 // Accept input from any player.
  52.                 return (IsNewButtonPress(button, PlayerIndex.One, out playerIndex) ||
  53.                         IsNewButtonPress(button, PlayerIndex.Two, out playerIndex) ||
  54.                         IsNewButtonPress(button, PlayerIndex.Three, out playerIndex) ||
  55.                         IsNewButtonPress(button, PlayerIndex.Four, out playerIndex));
  56.             }
  57.         }
RAW Paste Data