Files
evilsatellites/EvilSatellites/InputManager.cs
T

75 lines
1.9 KiB
C#
Raw Normal View History

2021-04-11 17:09:57 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2021-04-24 02:47:17 +02:00
using Microsoft.Xna.Framework;
2021-04-11 17:09:57 +02:00
using Microsoft.Xna.Framework.Input;
namespace EvilSatellites
{
public class InputManager
{
private KeyboardState OldKeyState;
private KeyboardState NewKeyState;
2021-04-24 02:47:17 +02:00
private GamePadState OldPadState;
private GamePadState NewPadState;
2021-04-11 17:09:57 +02:00
public InputManager()
{
OldKeyState = Keyboard.GetState();
NewKeyState = Keyboard.GetState();
2021-04-24 02:47:17 +02:00
OldPadState = GamePad.GetState(PlayerIndex.One);
NewPadState = GamePad.GetState(PlayerIndex.One);
2021-04-11 17:09:57 +02:00
}
public void Update()
{
OldKeyState = NewKeyState;
NewKeyState = Keyboard.GetState();
2021-04-24 02:47:17 +02:00
OldPadState = NewPadState;
NewPadState = GamePad.GetState(PlayerIndex.One);
2021-04-11 17:09:57 +02:00
}
public bool IsJustPressed(Keys key)
{
return (NewKeyState.IsKeyDown(key) && !OldKeyState.IsKeyDown(key));
}
public bool IsJustReleased(Keys key)
{
return !NewKeyState.IsKeyDown(key) && OldKeyState.IsKeyDown(key);
}
public bool IsPressed(Keys key)
{
return NewKeyState.IsKeyDown(key);
}
public bool IsReleased(Keys key)
{
return NewKeyState.IsKeyUp(key);
}
2021-04-24 02:47:17 +02:00
public bool IsJustPressed(Buttons key)
{
return (NewPadState.IsButtonDown(key) && !OldPadState.IsButtonDown(key));
}
public bool IsJustReleased(Buttons key)
{
return !NewPadState.IsButtonDown(key) && OldPadState.IsButtonDown(key);
}
public bool IsPressed(Buttons key)
{
return NewPadState.IsButtonDown(key);
}
public bool IsReleased(Buttons key)
{
return !NewPadState.IsButtonDown(key);
}
2021-04-11 17:09:57 +02:00
}
}