From 9d3171540df1d0acd04174a564459ab13b4ae4b6 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Wed, 3 Feb 2016 11:54:14 +0100 Subject: [PATCH] AssaultDashCheck is now in FirstPersonInputController instead. TODO: config option, shift button, forward/backward dash --- .../Engine/Input/FirstPersonInputController.h | 62 +++++++++++++++++++ include/Game/Systems/PlayerMovementSystem.h | 15 ----- src/Game/Systems/PlayerMovementSystem.cpp | 44 +------------ 3 files changed, 65 insertions(+), 56 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index d4c9071c..1efe4b75 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -25,6 +25,10 @@ public: virtual bool OnCommand(const Events::InputCommand& e) override; virtual void Reset(); + void AssaultDashCheck(double dt, bool isJumping); + virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; } + virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; } + protected: const int m_PlayerID; bool m_MouseLocked = false; @@ -33,6 +37,23 @@ protected: bool m_Jumping = false; bool m_DoubleJumping = false; bool m_Crouching = false; + //assault dash enum + enum class AssaultDashDirection { + Left, + Right, + Forward, + Backward, + None + }; + //assault dash membervariables + double m_AssaultDashDoubleTapDeltaTime = 0.0f; + double m_AssaultDashCoolDownTimer = 0.0f; + double m_AssaultDashCoolDownMaxTimer = 3.0f; + AssaultDashDirection m_AssaultDashDoubleTapLastKey = AssaultDashDirection::None; + const float m_AssaultDashDoubleTapSensitivityTimer = 0.25f; + AssaultDashDirection m_AssaultDashTapDirection = AssaultDashDirection::None; + bool m_AssaultDashDoubleTapped = false; + bool m_PlayerIsDashing = false; EventRelay m_ELockMouse; bool OnLockMouse(const Events::LockMouse& e); @@ -129,4 +150,45 @@ bool FirstPersonInputController::OnLockMouse(const Events::LockMou return true; } +template +void FirstPersonInputController::AssaultDashCheck(double dt, bool isJumping) { + auto controllerMovement = Movement(); + m_AssaultDashDoubleTapDeltaTime += dt; + m_AssaultDashCoolDownTimer -= dt; + //cooldown = m_AssaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work) + if (m_AssaultDashCoolDownTimer > (m_AssaultDashCoolDownMaxTimer - 0.25f)) { + m_PlayerIsDashing = true; + } else { + m_PlayerIsDashing = false; + } + //reset the DoubleTapped state in case we recently doubleTapped + if (m_AssaultDashDoubleTapped) { + m_AssaultDashDoubleTapped = false; + } + //Assault Dash logic: tap left or right twice within 0.5sec to activate the doubletap-dash + if (controllerMovement.x > 0 && controllerMovement.y == 0.f && controllerMovement.z == 0.f) { + if (m_AssaultDashDoubleTapLastKey != AssaultDashDirection::Right && m_AssaultDashDoubleTapDeltaTime < m_AssaultDashDoubleTapSensitivityTimer + && m_AssaultDashTapDirection == AssaultDashDirection::Right && m_AssaultDashCoolDownTimer <= 0.0f && !isJumping) { + m_AssaultDashDoubleTapped = true; + m_AssaultDashDoubleTapDeltaTime = 0.f; + m_AssaultDashCoolDownTimer = m_AssaultDashCoolDownMaxTimer; + } + m_AssaultDashDoubleTapLastKey = AssaultDashDirection::Right; + m_AssaultDashDoubleTapDeltaTime = 0.f; + m_AssaultDashTapDirection = AssaultDashDirection::Right; + } else if (controllerMovement.x < 0 && controllerMovement.y == 0.f && controllerMovement.z == 0.f) { + if (m_AssaultDashDoubleTapLastKey != AssaultDashDirection::Left && m_AssaultDashDoubleTapDeltaTime < m_AssaultDashDoubleTapSensitivityTimer + && m_AssaultDashTapDirection == AssaultDashDirection::Left && m_AssaultDashCoolDownTimer <= 0.0f && !isJumping) { + m_AssaultDashDoubleTapped = true; + m_AssaultDashDoubleTapDeltaTime = 0.f; + m_AssaultDashCoolDownTimer = m_AssaultDashCoolDownMaxTimer; + } + m_AssaultDashDoubleTapLastKey = AssaultDashDirection::Left; + m_AssaultDashDoubleTapDeltaTime = 0.f; + m_AssaultDashTapDirection = AssaultDashDirection::Left; + } else { + m_AssaultDashDoubleTapLastKey = AssaultDashDirection::None; + } +} + #endif \ No newline at end of file diff --git a/include/Game/Systems/PlayerMovementSystem.h b/include/Game/Systems/PlayerMovementSystem.h index 554d174e..34862e90 100644 --- a/include/Game/Systems/PlayerMovementSystem.h +++ b/include/Game/Systems/PlayerMovementSystem.h @@ -21,19 +21,4 @@ private: EventRelay m_EPlayerSpawned; bool OnPlayerSpawned(Events::PlayerSpawned& e); - double m_AssaultDashDoubleTapDeltaTime = 0.0f; - double m_AssaultDashCoolDownTimer = 0.0f; - double m_AssaultDashCoolDownMaxTimer = 3.0f; - ImGuiKey m_AssaultDashDoubleTapLastKey = ImGuiKey_Escape; - const float m_AssaultDashDoubleTapSensitivityTimer = 0.25f; - enum class AssaultDashDirection { - Left, - Right, - None - }; - AssaultDashDirection m_AssaultDashTapDirection = AssaultDashDirection::None; - bool m_AssaultDashDoubleTapped = false; - bool m_PlayerIsDashing = false; - - void assaultDashCheck(glm::vec3 controllerMovement, double dt, bool isJumping); }; \ No newline at end of file diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index c3eb1c84..70bbafb0 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -43,7 +43,7 @@ void PlayerMovementSystem::Update(double dt) ComponentWrapper cPhysics = player["Physics"]; //Assault Dash Check - //TODO: check if playerclass is assault! - assaultDashCheck(controller->Movement(), dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f); + controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f); glm::vec3 wishDirection = controller->Movement() * glm::inverse(glm::quat(ori)); float wishSpeed; if (controller->Crouching()) { @@ -74,14 +74,14 @@ void PlayerMovementSystem::Update(double dt) ImGui::InputFloat("surfaceFriction", &surfaceFriction); float accelerationSpeed = actualAccel * (float)dt * wishSpeed * surfaceFriction; //if doubleTapped do Assault Dash - but only boost maximum 50.0f - float doubleTapDashBoost = m_AssaultDashDoubleTapped ? 20.0f : 1.0f; + float doubleTapDashBoost = controller->AssaultDashDoubleTapped() ? 20.0f : 1.0f; accelerationSpeed = glm::min(doubleTapDashBoost*glm::min(accelerationSpeed, addSpeed), 50.0f); velocity += accelerationSpeed * wishDirection; ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity)); } //you cant jump and dash at the same time - since there is no friction in the air and we would thus dash much further in the air - if (!m_PlayerIsDashing && controller->Jumping() && !controller->Crouching() && (velocity.y == 0.f || !controller->DoubleJumping())) { + if (!controller->PlayerIsDashing() && controller->Jumping() && !controller->Crouching() && (velocity.y == 0.f || !controller->DoubleJumping())) { if (velocity.y == 0.f) { controller->SetDoubleJumping(false); } @@ -170,41 +170,3 @@ bool PlayerMovementSystem::OnPlayerSpawned(Events::PlayerSpawned& e) return true; } -void PlayerMovementSystem::assaultDashCheck(glm::vec3 controllerMovement, double dt, bool isJumping) { - m_AssaultDashDoubleTapDeltaTime += dt; - m_AssaultDashCoolDownTimer -= dt; - //cooldown = m_AssaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work) - if (m_AssaultDashCoolDownTimer > (m_AssaultDashCoolDownMaxTimer - 0.25f)) { - m_PlayerIsDashing = true; - } else { - m_PlayerIsDashing = false; - } - //reset the DoubleTapped state in case we recently doubleTapped - if (m_AssaultDashDoubleTapped) { - m_AssaultDashDoubleTapped = false; - } - //Assault Dash logic: tap left or right twice within 0.5sec to activate the doubletap-dash - if (controllerMovement.x > 0 && controllerMovement.y == 0.f && controllerMovement.z == 0.f) { - if (m_AssaultDashDoubleTapLastKey != ImGuiKey_RightArrow && m_AssaultDashDoubleTapDeltaTime < m_AssaultDashDoubleTapSensitivityTimer - && m_AssaultDashTapDirection == AssaultDashDirection::Right && m_AssaultDashCoolDownTimer <= 0.0f && !isJumping) { - m_AssaultDashDoubleTapped = true; - m_AssaultDashDoubleTapDeltaTime = 0.f; - m_AssaultDashCoolDownTimer = m_AssaultDashCoolDownMaxTimer; - } - m_AssaultDashDoubleTapLastKey = ImGuiKey_RightArrow; - m_AssaultDashDoubleTapDeltaTime = 0.f; - m_AssaultDashTapDirection = AssaultDashDirection::Right; - } else if (controllerMovement.x < 0 && controllerMovement.y == 0.f && controllerMovement.z == 0.f) { - if (m_AssaultDashDoubleTapLastKey != ImGuiKey_LeftArrow && m_AssaultDashDoubleTapDeltaTime < m_AssaultDashDoubleTapSensitivityTimer - && m_AssaultDashTapDirection == AssaultDashDirection::Left && m_AssaultDashCoolDownTimer <= 0.0f && !isJumping) { - m_AssaultDashDoubleTapped = true; - m_AssaultDashDoubleTapDeltaTime = 0.f; - m_AssaultDashCoolDownTimer = m_AssaultDashCoolDownMaxTimer; - } - m_AssaultDashDoubleTapLastKey = ImGuiKey_LeftArrow; - m_AssaultDashDoubleTapDeltaTime = 0.f; - m_AssaultDashTapDirection = AssaultDashDirection::Left; - } else { - m_AssaultDashDoubleTapLastKey = ImGuiKey_Escape; - } -}