GamePads.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // GamePads.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Input;
  15. #endregion
  16. namespace Spacewar
  17. {
  18. /// <summary>
  19. /// Easy access to a collection of gamepads
  20. /// </summary>
  21. public class GamePads
  22. {
  23. private GamePadHelper[] gamePads = new GamePadHelper[]
  24. {
  25. new GamePadHelper(PlayerIndex.One),
  26. new GamePadHelper(PlayerIndex.Two),
  27. new GamePadHelper(PlayerIndex.Three),
  28. new GamePadHelper(PlayerIndex.Four)
  29. };
  30. /// <summary>
  31. /// Returns the correct gamepad for a player
  32. /// </summary>
  33. /// <param name="player">Which player.</param>
  34. /// <returns></returns>
  35. public GamePadHelper this[PlayerIndex player]
  36. {
  37. get
  38. {
  39. return gamePads[(int)player];
  40. }
  41. }
  42. /// <summary>
  43. /// Updates the state of all gamepads so the XXXpressed functions will work. This method should be called once per frame
  44. /// </summary>
  45. public void Update(Game game, KeyboardState keyState)
  46. {
  47. foreach (GamePadHelper gamepad in gamePads)
  48. {
  49. gamepad.Update(game, keyState);
  50. }
  51. }
  52. }
  53. }