InputComponentManager.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // InputComponentManager.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 Microsoft.Xna.Framework;
  13. using Microsoft.Xna.Framework.Input;
  14. #endregion
  15. namespace RobotGameData.Input
  16. {
  17. /// <summary>
  18. /// It allows the creation of InputComponent up to 4, which is the maximum
  19. /// allowed number, and waits for the user’s inputs.
  20. /// </summary>
  21. public class InputComponentManager
  22. {
  23. #region Fields
  24. protected InputComponent[] inputComponents;
  25. #endregion
  26. /// <summary>
  27. /// Constructor.
  28. /// </summary>
  29. public InputComponentManager()
  30. {
  31. // create four input components
  32. inputComponents = new InputComponent[]
  33. {
  34. new InputComponent( PlayerIndex.One),
  35. new InputComponent( PlayerIndex.Two),
  36. new InputComponent( PlayerIndex.Three),
  37. new InputComponent( PlayerIndex.Four),
  38. };
  39. }
  40. /// <summary>
  41. /// Initialize all input components
  42. /// </summary>
  43. public void Initialize()
  44. {
  45. for( int i = 0; i < inputComponents.Length; i++)
  46. inputComponents[i].Initialize();
  47. }
  48. /// <summary>
  49. /// Reset all input components
  50. /// </summary>
  51. public void Reset()
  52. {
  53. for (int i = 0; i < inputComponents.Length; i++)
  54. inputComponents[i].Reset();
  55. }
  56. /// <summary>
  57. /// Update all input components
  58. /// </summary>
  59. public void Update(GameTime gameTime)
  60. {
  61. for (int i = 0; i < inputComponents.Length; i++)
  62. inputComponents[i].Update(gameTime);
  63. }
  64. public InputComponent GetInputComponent(PlayerIndex idx)
  65. {
  66. return inputComponents[(Int32)idx];
  67. }
  68. /// <summary>
  69. /// This is the function which does the input process before updating.
  70. /// </summary>
  71. public void PreUpdate()
  72. {
  73. for (int i = 0; i < inputComponents.Length; i++)
  74. inputComponents[i].PreUpdate();
  75. }
  76. /// <summary>
  77. /// This is the function which does the input process after updating.
  78. /// </summary>
  79. public void PostUpdate()
  80. {
  81. for (int i = 0; i < inputComponents.Length; i++)
  82. inputComponents[i].PostUpdate();
  83. }
  84. }
  85. }