-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputState.cs
More file actions
30 lines (23 loc) · 1.02 KB
/
Copy pathInputState.cs
File metadata and controls
30 lines (23 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using Microsoft.Xna.Framework.Input;
namespace FactoryGame;
internal sealed class InputState
{
private KeyboardState _prevKeyboard;
private KeyboardState _currKeyboard;
private MouseState _prevMouse;
private MouseState _currMouse;
public void Update()
{
_prevKeyboard = _currKeyboard;
_prevMouse = _currMouse;
_currKeyboard = Keyboard.GetState();
_currMouse = Mouse.GetState();
}
public bool KeyPressed(Keys key) => _currKeyboard.IsKeyDown(key) && !_prevKeyboard.IsKeyDown(key);
public bool KeyDown(Keys key) => _currKeyboard.IsKeyDown(key);
public bool LeftClicked => _currMouse.LeftButton == ButtonState.Pressed && _prevMouse.LeftButton == ButtonState.Released;
public bool RightClicked => _currMouse.RightButton == ButtonState.Pressed && _prevMouse.RightButton == ButtonState.Released;
public int ScrollDelta => _currMouse.ScrollWheelValue - _prevMouse.ScrollWheelValue;
public int MouseX => _currMouse.X;
public int MouseY => _currMouse.Y;
}