-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.cs
40 lines (34 loc) · 1.22 KB
/
Input.cs
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
31
32
33
34
35
36
37
38
39
40
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShrimpfulAdventure {
internal static class Input {
static KeyboardState kstate = default;
static KeyboardState oldKstate = default;
public static void Update() {
oldKstate = kstate;
kstate = Keyboard.GetState();
}
static bool KeyPressed(Keys key, bool thisFrame) {
return kstate[key] == KeyState.Down && (!thisFrame || oldKstate[key] == KeyState.Up);
}
public static bool JumpPressed() {
return KeyPressed(Keys.Up, true) || KeyPressed(Keys.W, true);
}
public static bool LeftPressed() {
return KeyPressed(Keys.Left, false) || KeyPressed(Keys.A, false);
}
public static bool RightPressed() {
return KeyPressed(Keys.Right, false) || KeyPressed(Keys.D, false);
}
public static bool InteractPressed() {
return KeyPressed(Keys.Down, true) || KeyPressed(Keys.S, true);
}
public static bool RestartPressed() {
return KeyPressed(Keys.R, true);
}
}
}