From b1148c0c6cc8f00272459c6c00ee5281345e48f6 Mon Sep 17 00:00:00 2001 From: Jocke Date: Thu, 3 Mar 2016 21:24:31 +0100 Subject: [PATCH 1/5] Added a afterimage SprintEffect for the Sniper. --- include/Game/Systems/PlayerMovementSystem.h | 2 + resources/Schema/Components/SprintAbility.xml | 1 + resources/Schema/Components/SprintAbility.xsd | 3 ++ resources/Schema/Entities/SprintEffect.xml | 25 ++++++++++++ src/Game/Systems/PlayerMovementSystem.cpp | 40 ++++++++++++++++++- 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 resources/Schema/Entities/SprintEffect.xml diff --git a/include/Game/Systems/PlayerMovementSystem.h b/include/Game/Systems/PlayerMovementSystem.h index bf7b4718..981fc13a 100644 --- a/include/Game/Systems/PlayerMovementSystem.h +++ b/include/Game/Systems/PlayerMovementSystem.h @@ -30,6 +30,8 @@ private: bool m_LeftFoot = false; // To get a difference when calculating the walking state. glm::vec3 m_LastPosition = glm::vec3(); + // Used to track afterimages for sprint effect. + float m_SprintEffectTimer; // The logic for making the sound play when player is moving void playerStep(double dt); // Spawn a hexagon at origin of an Entity diff --git a/resources/Schema/Components/SprintAbility.xml b/resources/Schema/Components/SprintAbility.xml index 5cc59a3a..578c0017 100644 --- a/resources/Schema/Components/SprintAbility.xml +++ b/resources/Schema/Components/SprintAbility.xml @@ -1,4 +1,5 @@ 2.0 + false \ No newline at end of file diff --git a/resources/Schema/Components/SprintAbility.xsd b/resources/Schema/Components/SprintAbility.xsd index 9eabb450..7fe0d65a 100644 --- a/resources/Schema/Components/SprintAbility.xsd +++ b/resources/Schema/Components/SprintAbility.xsd @@ -12,6 +12,9 @@ This is the strength of the sprint effect + + True if currently sprinting. + diff --git a/resources/Schema/Entities/SprintEffect.xml b/resources/Schema/Entities/SprintEffect.xml new file mode 100644 index 00000000..ab897cf5 --- /dev/null +++ b/resources/Schema/Entities/SprintEffect.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + 0.1 + + + + 0.1 + + + + + + + + + + diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index b116bcd9..8d0ff990 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -2,6 +2,7 @@ PlayerMovementSystem::PlayerMovementSystem(SystemParams params) : System(params) + , m_SprintEffectTimer(0.f) { EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &PlayerMovementSystem::OnDoubleJump); @@ -19,8 +20,42 @@ void PlayerMovementSystem::Update(double dt) { updateMovementControllers(dt); // Only do physics calculations on client and only for themselves. - if (IsClient && LocalPlayer.Valid()) { - updateVelocity(LocalPlayer, dt); + if (IsClient) { + if (LocalPlayer.Valid()){ + updateVelocity(LocalPlayer, dt); + } + m_SprintEffectTimer += dt; + if (m_SprintEffectTimer < 0.016f) { + return; + } + m_SprintEffectTimer = 0.f; + const ComponentPool* pool = m_World->GetComponents("SprintAbility"); + if (pool == nullptr) { + return; + } + for (auto cSprint : *pool) { + if (/*cSprint.EntityID != LocalPlayer.ID && */(bool)cSprint["Active"]) { + // Spawn one afterimage for each player that sprints. + EntityWrapper player(m_World, cSprint.EntityID); + auto entityFile = ResourceManager::Load("Schema/Entities/SprintEffect.xml"); + EntityWrapper dashEffect = entityFile->MergeInto(m_World); + auto playerModel = player.FirstChildByName("PlayerModel"); + if (!playerModel.Valid()) { + continue; + } + auto playerEntityModel = playerModel["Model"]; + auto playerEntityAnimation = playerModel["Animation"]; + playerEntityModel.Copy(dashEffect["Model"]); + playerEntityAnimation.Copy(dashEffect["Animation"]); + dashEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"]; + ((glm::vec4&)dashEffect["ExplosionEffect"]["EndColor"]).w = 0.f; + dashEffect["Animation"]["Speed1"] = 0.0; + dashEffect["Animation"]["Speed2"] = 0.0; + dashEffect["Animation"]["Speed3"] = 0.0; + dashEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"]; + dashEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"]; + } + } } } @@ -64,6 +99,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt) } bool sniperSprinting = false; if (player.HasComponent("SprintAbility")) { + (bool)player["SprintAbility"]["Active"] = controller->SpecialAbilityKeyDown(); if (controller->SpecialAbilityKeyDown()) { playerMovementSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"]; playerCrouchSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"]; From 984b8ad3e9a8b588bdecb5e46bb918c19b0113c6 Mon Sep 17 00:00:00 2001 From: Jocke Date: Thu, 3 Mar 2016 21:57:27 +0100 Subject: [PATCH 2/5] SprintEffect defaults to 30% extra speed. --- resources/Schema/Components/SprintAbility.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/Schema/Components/SprintAbility.xml b/resources/Schema/Components/SprintAbility.xml index 578c0017..d9727ed9 100644 --- a/resources/Schema/Components/SprintAbility.xml +++ b/resources/Schema/Components/SprintAbility.xml @@ -1,5 +1,5 @@ - 2.0 + 1.3 false \ No newline at end of file From ae13a2db6b8df273d1490f1ecf9bf6215b28a6c5 Mon Sep 17 00:00:00 2001 From: Jocke Date: Thu, 3 Mar 2016 22:09:51 +0100 Subject: [PATCH 3/5] Player cannot see their own sprint effect. --- src/Game/Systems/PlayerMovementSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 8d0ff990..ab4ac6a1 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -34,7 +34,7 @@ void PlayerMovementSystem::Update(double dt) return; } for (auto cSprint : *pool) { - if (/*cSprint.EntityID != LocalPlayer.ID && */(bool)cSprint["Active"]) { + if (cSprint.EntityID != LocalPlayer.ID && (bool)cSprint["Active"]) { // Spawn one afterimage for each player that sprints. EntityWrapper player(m_World, cSprint.EntityID); auto entityFile = ResourceManager::Load("Schema/Entities/SprintEffect.xml"); From 0398006fdcb023af4162c2be60c92fde0aa08f0e Mon Sep 17 00:00:00 2001 From: Jocke Date: Fri, 4 Mar 2016 03:19:41 +0100 Subject: [PATCH 4/5] added safety ifs and renamed dasheffect to sprinteffect --- src/Game/Systems/PlayerMovementSystem.cpp | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index ab4ac6a1..025a8b70 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -38,22 +38,28 @@ void PlayerMovementSystem::Update(double dt) // Spawn one afterimage for each player that sprints. EntityWrapper player(m_World, cSprint.EntityID); auto entityFile = ResourceManager::Load("Schema/Entities/SprintEffect.xml"); - EntityWrapper dashEffect = entityFile->MergeInto(m_World); + EntityWrapper sprintEffect = entityFile->MergeInto(m_World); auto playerModel = player.FirstChildByName("PlayerModel"); if (!playerModel.Valid()) { continue; } + if (!playerModel.HasComponent("Model")) { + continue; + } + if (!playerModel.HasComponent("Animation")) { + continue; + } auto playerEntityModel = playerModel["Model"]; auto playerEntityAnimation = playerModel["Animation"]; - playerEntityModel.Copy(dashEffect["Model"]); - playerEntityAnimation.Copy(dashEffect["Animation"]); - dashEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"]; - ((glm::vec4&)dashEffect["ExplosionEffect"]["EndColor"]).w = 0.f; - dashEffect["Animation"]["Speed1"] = 0.0; - dashEffect["Animation"]["Speed2"] = 0.0; - dashEffect["Animation"]["Speed3"] = 0.0; - dashEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"]; - dashEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"]; + playerEntityModel.Copy(sprintEffect["Model"]); + playerEntityAnimation.Copy(sprintEffect["Animation"]); + sprintEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"]; + ((glm::vec4&)sprintEffect["ExplosionEffect"]["EndColor"]).w = 0.f; + sprintEffect["Animation"]["Speed1"] = 0.0; + sprintEffect["Animation"]["Speed2"] = 0.0; + sprintEffect["Animation"]["Speed3"] = 0.0; + sprintEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"]; + sprintEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"]; } } } From 2507516a85c049925dea86e4239b1393934e9bd2 Mon Sep 17 00:00:00 2001 From: Jocke Date: Fri, 4 Mar 2016 03:28:58 +0100 Subject: [PATCH 5/5] Tweaked values for the effect to look better --- resources/Schema/Entities/SprintEffect.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/Schema/Entities/SprintEffect.xml b/resources/Schema/Entities/SprintEffect.xml index ab897cf5..6e892f8f 100644 --- a/resources/Schema/Entities/SprintEffect.xml +++ b/resources/Schema/Entities/SprintEffect.xml @@ -8,11 +8,11 @@ - 0.1 + 0.15 - 0.1 + 0.15