From 45a92b362f6877695715566e9ef22b42b493c5a8 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Tue, 2 Feb 2016 15:10:11 +0100 Subject: [PATCH] DoubleJumping now in InputController instead. --- include/Engine/Input/FirstPersonInputController.h | 15 ++++++++++----- include/Game/Systems/PlayerMovementSystem.h | 2 -- src/Game/Systems/PlayerMovementSystem.cpp | 6 +++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index 426670c4..d4c9071c 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -15,7 +15,11 @@ public: virtual const glm::vec3 Rotation() const { return m_Rotation; } virtual bool Jumping() const { return m_Jumping; } virtual bool Crouching() const { return m_Crouching; } - + virtual bool DoubleJumping() const { return m_DoubleJumping; } + virtual void SetDoubleJumping(bool isDoubleJumping) { + m_DoubleJumping = isDoubleJumping; + } + void LockMouse(); void UnlockMouse(); virtual bool OnCommand(const Events::InputCommand& e) override; @@ -27,8 +31,9 @@ protected: glm::vec3 m_Rotation; glm::vec3 m_Movement; bool m_Jumping = false; + bool m_DoubleJumping = false; bool m_Crouching = false; - + EventRelay m_ELockMouse; bool OnLockMouse(const Events::LockMouse& e); EventRelay m_EUnlockMouse; @@ -36,7 +41,7 @@ protected: }; template -FirstPersonInputController::FirstPersonInputController(EventBroker* eventBroker, int playerID) +FirstPersonInputController::FirstPersonInputController(EventBroker* eventBroker, int playerID) : InputController(eventBroker) , m_PlayerID(playerID) { @@ -113,14 +118,14 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm template bool FirstPersonInputController::OnUnlockMouse(const Events::UnlockMouse& e) { - m_MouseLocked = false; + m_MouseLocked = false; return true; } template bool FirstPersonInputController::OnLockMouse(const Events::LockMouse& e) { - m_MouseLocked = true; + m_MouseLocked = true; return true; } diff --git a/include/Game/Systems/PlayerMovementSystem.h b/include/Game/Systems/PlayerMovementSystem.h index 4fbb2c79..f39740ec 100644 --- a/include/Game/Systems/PlayerMovementSystem.h +++ b/include/Game/Systems/PlayerMovementSystem.h @@ -20,6 +20,4 @@ private: EventRelay m_EPlayerSpawned; bool OnPlayerSpawned(Events::PlayerSpawned& e); - - bool m_DoubleJumped = false; }; \ No newline at end of file diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 868751f7..72900d7a 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -76,12 +76,12 @@ void PlayerMovementSystem::Update(double dt) ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity)); } - if (controller->Jumping() && !controller->Crouching() && (velocity.y == 0.f || !m_DoubleJumped)) { + if (controller->Jumping() && !controller->Crouching() && (velocity.y == 0.f || !controller->DoubleJumping())) { if (velocity.y == 0.f) { - m_DoubleJumped = false; + controller->SetDoubleJumping(false); } else { - m_DoubleJumped = true; + controller->SetDoubleJumping(true); } velocity.y += 4.f; }