From fd9f68e4f848b8154aa013a078ad6a49828284b2 Mon Sep 17 00:00:00 2001 From: Hannes Mann Date: Mon, 13 Jun 2016 17:06:13 +0200 Subject: [PATCH] Add keyboard mappings to N64 controller These should be accurate to the original PC game The plan is to make these rebindable --- src/input/input_state.h | 2 +- src/input/standalone_input_provider.cc | 59 +++++++++++++++++++++++++- src/input/standalone_input_provider.h | 1 + 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/input/input_state.h b/src/input/input_state.h index 59bd3be..94c2433 100644 --- a/src/input/input_state.h +++ b/src/input/input_state.h @@ -22,7 +22,7 @@ namespace openrayman a = (1 << 6), b = (1 << 7), - // The triggers. + // The triggers. Used for targeting and info l = (1 << 8), r = (1 << 9), z = (1 << 10), diff --git a/src/input/standalone_input_provider.cc b/src/input/standalone_input_provider.cc index 36ea348..cf9dd54 100644 --- a/src/input/standalone_input_provider.cc +++ b/src/input/standalone_input_provider.cc @@ -21,8 +21,63 @@ namespace openrayman const input_state& standalone_input_provider::poll() { m_input.stick_x = m_input.stick_y = m_input.buttons = m_input.commands = 0; - if(glfwGetKey(m_window, GLFW_KEY_F11) == GLFW_PRESS) - m_input.commands |= input_command::toggle_fullscreen; + poll_keyboard(); return m_input; } + + void standalone_input_provider::poll_keyboard() + { + // Keyboard + // This is not 100% accurate to the original PC version because + // the N64 version is not the same as the PC version + // TODO: rebindable keyboard controls + // and controller... + + // Control stick + // This simulates a slower walk done by the control stick + // Used in some areas to avoid pirates + // TODO: Is half (64) accurate?!?! + int walk_strength = glfwGetKey(m_window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS ? 64 : 127; + + if(glfwGetKey(m_window, GLFW_KEY_LEFT) == GLFW_PRESS) + m_input.stick_x -= walk_strength; + if(glfwGetKey(m_window, GLFW_KEY_RIGHT) == GLFW_PRESS) + m_input.stick_x += walk_strength; + if(glfwGetKey(m_window, GLFW_KEY_UP) == GLFW_PRESS) + m_input.stick_y -= walk_strength; + if(glfwGetKey(m_window, GLFW_KEY_DOWN) == GLFW_PRESS) + m_input.stick_y += walk_strength; + + // Front buttons + if(glfwGetKey(m_window, GLFW_KEY_SPACE) == GLFW_PRESS) + m_input.buttons |= input_button::a; + if(glfwGetKey(m_window, GLFW_KEY_A) == GLFW_PRESS) + m_input.buttons |= input_button::b; + + // Triggers + if(glfwGetKey(m_window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) + m_input.buttons |= input_button::z; + if(glfwGetKey(m_window, GLFW_KEY_F1) == GLFW_PRESS) + m_input.buttons |= input_button::l; + if(glfwGetKey(m_window, GLFW_KEY_J) == GLFW_PRESS) + m_input.buttons |= input_button::r; + + // Start button + if(glfwGetKey(m_window, GLFW_KEY_ESCAPE) == GLFW_PRESS) + m_input.buttons |= input_button::start; + + // C buttons + if(glfwGetKey(m_window, GLFW_KEY_Q) == GLFW_PRESS) + m_input.commands |= input_button::cbtn_left; + if(glfwGetKey(m_window, GLFW_KEY_W) == GLFW_PRESS) + m_input.commands |= input_button::cbtn_right; + if(glfwGetKey(m_window, GLFW_KEY_O) == GLFW_PRESS) + m_input.commands |= input_button::cbtn_up; + if(glfwGetKey(m_window, GLFW_KEY_END) == GLFW_PRESS) + m_input.commands |= input_button::cbtn_down; + + // Commands + if(glfwGetKey(m_window, GLFW_KEY_F11) == GLFW_PRESS) + m_input.commands |= input_command::toggle_fullscreen; + } } diff --git a/src/input/standalone_input_provider.h b/src/input/standalone_input_provider.h index 71fbfb8..90bdf23 100644 --- a/src/input/standalone_input_provider.h +++ b/src/input/standalone_input_provider.h @@ -19,6 +19,7 @@ public: const std::string get_description() const override; const input_state& poll() override; private: + void poll_keyboard(); input_state m_input; GLFWwindow* m_window; };