Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using Microsoft.Xna.Framework.Net;
- using Microsoft.Xna.Framework.Storage;
- namespace STGED.STGEngine
- {
- public class InputManager : Microsoft.Xna.Framework.GameComponent
- {
- // Current input states
- public static GamePadState currentGPState = GamePad.GetState(PlayerIndex.One);
- public static KeyboardState currentKBState = Keyboard.GetState();
- // Previous input states
- public static GamePadState previousGPState;
- public static KeyboardState previousKBState;
- public override void Initialize()
- {
- previousGPState = GamePad.GetState(PlayerIndex.One);
- previousKBState = Keyboard.GetState();
- base.Initialize();
- }
- #region GamePad
- public static bool ButtonPush(Buttons button)
- {
- return (currentGPState.IsConnected && previousGPState.IsConnected && currentGPState.IsButtonDown(button) && previousGPState.IsButtonUp(button));
- }
- public static bool ButtonPull(Buttons button)
- {
- return (currentGPState.IsConnected && previousGPState.IsConnected && currentGPState.IsButtonUp(button) && previousGPState.IsButtonDown(button));
- }
- public static bool ButtonHold(Buttons button)
- {
- return (currentGPState.IsConnected && previousGPState.IsConnected && currentGPState.IsButtonDown(button) && previousGPState.IsButtonDown(button));
- }
- public static bool ButtonFree(Buttons button)
- {
- return (currentGPState.IsConnected && previousGPState.IsConnected && currentGPState.IsButtonUp(button) && previousGPState.IsButtonUp(button));
- }
- #endregion
- #region Keyboard
- public static bool KeyPush(Keys key)
- {
- return (currentKBState.IsKeyDown(key) && previousKBState.IsKeyUp(key));
- }
- public static bool KeyPull(Keys key)
- {
- return (currentKBState.IsKeyUp(key) && previousKBState.IsKeyDown(key));
- }
- public static bool KeyHold(Keys key)
- {
- return (currentKBState.IsKeyDown(key) && previousKBState.IsKeyDown(key));
- }
- public static bool KeyFree(Keys key)
- {
- return (currentKBState.IsKeyUp(key) && previousKBState.IsKeyUp(key));
- }
- #endregion
- #region Virtual keyboard
- public static bool VKPush(VirtualKey VK)
- {
- return (ButtonPush(VK.Button) || KeyPush(VK.Key));
- }
- public static bool VKPull(VirtualKey VK)
- {
- return (ButtonPull(VK.Button) || KeyPull(VK.Key));
- }
- public static bool VKHold(VirtualKey VK)
- {
- return (ButtonHold(VK.Button) || KeyHold(VK.Key));
- }
- public static bool VKFree(VirtualKey VK)
- {
- return (ButtonFree(VK.Button) || KeyFree(VK.Key));
- }
- #endregion
- public override void Update(GameTime gameTime)
- {
- previousGPState = currentGPState;
- previousKBState = currentKBState;
- currentGPState = GamePad.GetState(PlayerIndex.One);
- currentKBState = Keyboard.GetState();
- base.Update(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement