Advertisement
Guest User

Untitled

a guest
May 19th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. using Microsoft.Xna.Framework.Net;
  12. using Microsoft.Xna.Framework.Storage;
  13.  
  14. namespace STGED.STGEngine
  15. {
  16. public class InputManager : Microsoft.Xna.Framework.GameComponent
  17. {
  18. // Current input states
  19. public static GamePadState currentGPState = GamePad.GetState(PlayerIndex.One);
  20. public static KeyboardState currentKBState = Keyboard.GetState();
  21.  
  22. // Previous input states
  23. public static GamePadState previousGPState;
  24. public static KeyboardState previousKBState;
  25.  
  26. public override void Initialize()
  27. {
  28. previousGPState = GamePad.GetState(PlayerIndex.One);
  29. previousKBState = Keyboard.GetState();
  30.  
  31. base.Initialize();
  32. }
  33.  
  34. #region GamePad
  35. public static bool ButtonPush(Buttons button)
  36. {
  37. return (currentGPState.IsConnected && previousGPState.IsConnected && currentGPState.IsButtonDown(button) && previousGPState.IsButtonUp(button));
  38. }
  39.  
  40. public static bool ButtonPull(Buttons button)
  41. {
  42. return (currentGPState.IsConnected && previousGPState.IsConnected && currentGPState.IsButtonUp(button) && previousGPState.IsButtonDown(button));
  43. }
  44.  
  45. public static bool ButtonHold(Buttons button)
  46. {
  47. return (currentGPState.IsConnected && previousGPState.IsConnected && currentGPState.IsButtonDown(button) && previousGPState.IsButtonDown(button));
  48. }
  49.  
  50. public static bool ButtonFree(Buttons button)
  51. {
  52. return (currentGPState.IsConnected && previousGPState.IsConnected && currentGPState.IsButtonUp(button) && previousGPState.IsButtonUp(button));
  53. }
  54. #endregion
  55.  
  56. #region Keyboard
  57. public static bool KeyPush(Keys key)
  58. {
  59. return (currentKBState.IsKeyDown(key) && previousKBState.IsKeyUp(key));
  60. }
  61.  
  62. public static bool KeyPull(Keys key)
  63. {
  64. return (currentKBState.IsKeyUp(key) && previousKBState.IsKeyDown(key));
  65. }
  66.  
  67. public static bool KeyHold(Keys key)
  68. {
  69. return (currentKBState.IsKeyDown(key) && previousKBState.IsKeyDown(key));
  70. }
  71.  
  72. public static bool KeyFree(Keys key)
  73. {
  74. return (currentKBState.IsKeyUp(key) && previousKBState.IsKeyUp(key));
  75. }
  76. #endregion
  77.  
  78. #region Virtual keyboard
  79. public static bool VKPush(VirtualKey VK)
  80. {
  81. return (ButtonPush(VK.Button) || KeyPush(VK.Key));
  82. }
  83.  
  84. public static bool VKPull(VirtualKey VK)
  85. {
  86. return (ButtonPull(VK.Button) || KeyPull(VK.Key));
  87. }
  88.  
  89. public static bool VKHold(VirtualKey VK)
  90. {
  91. return (ButtonHold(VK.Button) || KeyHold(VK.Key));
  92. }
  93.  
  94. public static bool VKFree(VirtualKey VK)
  95. {
  96. return (ButtonFree(VK.Button) || KeyFree(VK.Key));
  97. }
  98. #endregion
  99.  
  100. public override void Update(GameTime gameTime)
  101. {
  102. previousGPState = currentGPState;
  103. previousKBState = currentKBState;
  104.  
  105. currentGPState = GamePad.GetState(PlayerIndex.One);
  106. currentKBState = Keyboard.GetState();
  107.  
  108. base.Update(gameTime);
  109. }
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement