From f163e8f37123e651ea80b690793845b31ddb8639 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Wed, 6 Apr 2022 20:52:51 -0700 Subject: Changeset: 2 Work on moving infrastruture to this project --- source/Player.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 source/Player.cpp (limited to 'source/Player.cpp') 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 PlayerKeyBinds::GetKeyArray() { + return { &keyLeft, kPlayerKeyBindCount }; +} +std::span 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; + } + } +} -- cgit v1.2.3-70-g09d2