-
Notifications
You must be signed in to change notification settings - Fork 1
/
Input.h
52 lines (39 loc) · 1.18 KB
/
Input.h
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
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef INPUT_H
#define INPUT_H
#include <vector>
#include "Entity.h"
struct KeyboardInputState
{
bool keyIsDown;
bool keyWasDown;
[[nodiscard]] inline bool pressedThisFrame() const
{
return keyIsDown && !keyWasDown;
}
[[nodiscard]] inline bool releasedThisFrame() const
{
return !keyIsDown && keyWasDown;
}
};
struct KeyboardInput
{
KeyboardInputState A;
KeyboardInputState B;
KeyboardInputState up;
KeyboardInputState down;
KeyboardInputState left;
KeyboardInputState right;
KeyboardInputState select;
KeyboardInputState start;
void setKey(sf::Keyboard::Key keycode, bool pressed);
void updateWasDown(const KeyboardInput &previousInput);
};
extern const std::vector<sf::Keyboard::Key> ALL_KEYS;
void updateKeyboardInputs(KeyboardInput& currentInput,
KeyboardInput& previousInput,
sf::Keyboard::Key knownKey,
bool isPressed);
std::vector<KeyboardInput> generateInputs(
const std::vector<std::vector<sf::Keyboard::Key>>& keyInputs);
KeyboardInput nextInput(std::vector<KeyboardInput> keyboardInputs, size_t idx);
#endif