diff options
Diffstat (limited to 'source/Player.cpp')
-rw-r--r-- | source/Player.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/source/Player.cpp b/source/Player.cpp new file mode 100644 index 0000000..6575820 --- /dev/null +++ b/source/Player.cpp @@ -0,0 +1,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; + } + } +} |