-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.hpp
More file actions
58 lines (45 loc) · 920 Bytes
/
Input.hpp
File metadata and controls
58 lines (45 loc) · 920 Bytes
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
53
54
55
56
57
#pragma once
#include "../GlfwWindow.hpp"
#include <vector>
enum class KEY_TYPE
{
UP = GLFW_KEY_UP,
DOWN = GLFW_KEY_DOWN,
LEFT = GLFW_KEY_LEFT,
RIGHT = GLFW_KEY_RIGHT,
W = 'W',
A = 'A',
S = 'S',
D = 'D',
Q = 'Q',
E = 'E',
};
enum class KEY_STATE
{
NONE,
PRESS,
DOWN,
UP,
END
};
enum
{
KEY_TYPE_COUNT = static_cast<int32_t>(UINT8_MAX + 1),
KEY_STATE_COUNT = static_cast<int32_t>(KEY_STATE::END),
};
class Input
{
public:
void Init();
void Update();
// 누르고 있을 때
bool GetButton(KEY_TYPE key) { return GetState(key) == KEY_STATE::PRESS; }
// 맨 처음 눌렀을 때
bool GetButtonDown(KEY_TYPE key) { return GetState(key) == KEY_STATE::DOWN; }
// 맨 처음 눌렀다 뗐을 때
bool GetButtonUp(KEY_TYPE key) { return GetState(key) == KEY_STATE::UP; }
private:
inline KEY_STATE GetState(KEY_TYPE key) { return _states[static_cast<uint8_t>(key)]; }
private:
std::vector<KEY_STATE> _states;
};