blob: 6575820762d7c85447472c07b5e8d4e49dc4cded (
plain)
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
|
#include "Player.hpp"
// Keep the same number as # of fields in `struct {}` in PlayerKeyBinds
constexpr int kPlayerKeyBindCount = 4;
// Here be dragons: this treats consecutive fiels as an array, technically UB
std::span<int> PlayerKeyBinds::GetKeyArray() {
return { &keyLeft, kPlayerKeyBindCount };
}
std::span<bool> PlayerKeyBinds::GetKeyStatusArray() {
return { &pressedLeft, kPlayerKeyBindCount };
}
void Player::Awaken() {
}
void Player::Resleep() {
}
void Player::Update() {
if (keybinds.pressedLeft) {
}
if (keybinds.pressedRight) {
}
// TODO jump controller
// TODO attack controller
}
void Player::HandleKeyInput(int key, int action) {
bool pressed;
if (action == GLFW_PRESS) {
pressed = true;
} else if (action == GLFW_REPEAT) {
return;
} else /* action == GLFW_RELEASE */ {
pressed = false;
}
for (int i = 0; i < kPlayerKeyBindCount; ++i) {
int kbKey = keybinds.GetKeyArray()[i];
bool& kbStatus = keybinds.GetKeyStatusArray()[i];
if (kbKey == key) {
kbStatus = pressed;
break;
}
}
}
|