aboutsummaryrefslogtreecommitdiff
path: root/source/Player.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-04-06 20:52:51 -0700
committerrtk0c <[email protected]>2022-04-06 20:52:51 -0700
commitf163e8f37123e651ea80b690793845b31ddb8639 (patch)
treee2c9f14d600f073533c9d01cfb90c4d60938127c /source/Player.cpp
parent11edae3fbf770695d1b263712ca4f3a40bdd70e3 (diff)
Changeset: 2 Work on moving infrastruture to this project
Diffstat (limited to 'source/Player.cpp')
-rw-r--r--source/Player.cpp50
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;
+ }
+ }
+}