From e4145cf2920ee6ab3fec6f5ada880699600dc336 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Sun, 13 Mar 2016 22:49:24 +0100 Subject: [PATCH 1/4] Fixed dash effect to be supported with the new animations using Fade components. Added bool Loop field in Fade component. --- include/Game/Systems/PlayerMovementSystem.h | 2 + resources/Schema/Components/BoostAssault.xml | 2 +- resources/Schema/Components/Fade.xml | 1 + resources/Schema/Components/Fade.xsd | 3 + resources/Schema/Entities/DashEffect.xml | 13 --- src/Game/Systems/FadeSystem.cpp | 4 +- src/Game/Systems/PlayerMovementSystem.cpp | 85 ++++++++++++++------ 7 files changed, 69 insertions(+), 41 deletions(-) delete mode 100644 resources/Schema/Entities/DashEffect.xml diff --git a/include/Game/Systems/PlayerMovementSystem.h b/include/Game/Systems/PlayerMovementSystem.h index feb1951e..60d25a42 100644 --- a/include/Game/Systems/PlayerMovementSystem.h +++ b/include/Game/Systems/PlayerMovementSystem.h @@ -32,6 +32,8 @@ private: glm::vec3 m_LastPosition = glm::vec3(); // Used to track afterimages for sprint effect. float m_SprintEffectTimer; + // Used to track afterimages for dash effect. + float m_DashEffectTimer; // The logic for making the sound play when player is moving void playerStep(double dt, EntityWrapper player); // Spawn a hexagon at origin of an Entity diff --git a/resources/Schema/Components/BoostAssault.xml b/resources/Schema/Components/BoostAssault.xml index c76fe21e..29378aec 100644 --- a/resources/Schema/Components/BoostAssault.xml +++ b/resources/Schema/Components/BoostAssault.xml @@ -1,4 +1,4 @@ - 2 + 1.35 diff --git a/resources/Schema/Components/Fade.xml b/resources/Schema/Components/Fade.xml index 94c942ca..2383b2a4 100644 --- a/resources/Schema/Components/Fade.xml +++ b/resources/Schema/Components/Fade.xml @@ -3,5 +3,6 @@ 1 true + true false \ No newline at end of file diff --git a/resources/Schema/Components/Fade.xsd b/resources/Schema/Components/Fade.xsd index 9c638258..c019678c 100644 --- a/resources/Schema/Components/Fade.xsd +++ b/resources/Schema/Components/Fade.xsd @@ -11,6 +11,9 @@ If the entity should fade out or in. + + If the effect should loop when it is done. + If the entity should reverse the fade after finishing, this will double the speed. diff --git a/resources/Schema/Entities/DashEffect.xml b/resources/Schema/Entities/DashEffect.xml deleted file mode 100644 index 6f28784d..00000000 --- a/resources/Schema/Entities/DashEffect.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - 0.5 - - - - - - - diff --git a/src/Game/Systems/FadeSystem.cpp b/src/Game/Systems/FadeSystem.cpp index 88460d53..f0e83eb5 100644 --- a/src/Game/Systems/FadeSystem.cpp +++ b/src/Game/Systems/FadeSystem.cpp @@ -24,14 +24,14 @@ void FadeSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cFade, currentTime += dTime; if(currentTime > fadeTime) { - currentTime = 0.0; + currentTime = 0.0 + fadeTime * (bool)cFade["Loop"]; if ((bool)cFade["Reverse"]) { (Field)cFade["Out"] = !(bool)cFade["Out"]; currentTime = fadeTime; } } if(currentTime < 0.0) { - currentTime = fadeTime; + currentTime = fadeTime * (bool)cFade["Loop"]; if ((bool)cFade["Reverse"]) { (Field)cFade["Out"] = !(bool)cFade["Out"]; currentTime = 0.0; diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 3cf1068d..7b49f474 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -3,6 +3,7 @@ PlayerMovementSystem::PlayerMovementSystem(SystemParams params) : System(params) , m_SprintEffectTimer(0.f) + , m_DashEffectTimer(0.f) { EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &PlayerMovementSystem::OnDoubleJump); @@ -24,23 +25,57 @@ void PlayerMovementSystem::Update(double dt) if (LocalPlayer.Valid()){ updateVelocity(LocalPlayer, dt); } - - - m_SprintEffectTimer += dt; - if (m_SprintEffectTimer < 0.016f) { + //m_SprintEffectTimer += dt; + //if (m_SprintEffectTimer < 0.016f) { + // return; + //} + //m_SprintEffectTimer = 0.f; + //auto 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 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(sprintEffect["Model"]); + // playerEntityAnimation.Copy(sprintEffect["Animation"]); + // sprintEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"]; + // ((Field)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"]; + // } + //} + m_DashEffectTimer += dt; + if (m_DashEffectTimer < 0.046f) { return; } - m_SprintEffectTimer = 0.f; - auto pool = m_World->GetComponents("SprintAbility"); + m_DashEffectTimer = 0.f; + auto pool = m_World->GetComponents("DashAbility"); 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 sprintEffect = entityFile->MergeInto(m_World); + for (auto cDash : *pool) { + if (cDash.EntityID != LocalPlayer.ID && (double)cDash["CoolDownMaxTimer"] - (double)cDash["CoolDownTimer"] < 0.5) { + // Spawn one afterimage for each player that Dashes. + EntityWrapper player(m_World, cDash.EntityID); auto playerModel = player.FirstChildByName("PlayerModel"); if (!playerModel.Valid()) { continue; @@ -48,20 +83,20 @@ void PlayerMovementSystem::Update(double dt) if (!playerModel.HasComponent("Model")) { continue; } - if (!playerModel.HasComponent("Animation")) { - continue; - } auto playerEntityModel = playerModel["Model"]; - auto playerEntityAnimation = playerModel["Animation"]; - playerEntityModel.Copy(sprintEffect["Model"]); - playerEntityAnimation.Copy(sprintEffect["Animation"]); - sprintEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"]; - ((Field)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"]; + EntityWrapper dashEffect = playerModel.Clone(); + playerEntityModel.Copy(dashEffect["Model"]); + for (auto& cAnim : dashEffect.ChildrenWithComponent("Animation")) { + cAnim["Animation"]["Play"] = false; + } + dashEffect.AttachComponent("Lifetime"); + dashEffect.AttachComponent("Fade"); + dashEffect["Fade"]["Loop"] = false; + dashEffect["Fade"]["FadeTime"] = 0.5; + dashEffect["Fade"]["Time"] = (double)dashEffect["Fade"]["FadeTime"]; + dashEffect["Lifetime"]["Lifetime"] = (double)dashEffect["Fade"]["FadeTime"]; + dashEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"]; + dashEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"]; } } } From 0084224e18c00607909ac55d322daf2e7ea60e5b Mon Sep 17 00:00:00 2001 From: William Moberg Date: Sun, 13 Mar 2016 23:23:05 +0100 Subject: [PATCH 2/4] WIP, dash effect fade weapon. --- src/Game/Systems/PlayerMovementSystem.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 7b49f474..74a8de7e 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -64,7 +64,7 @@ void PlayerMovementSystem::Update(double dt) // } //} m_DashEffectTimer += dt; - if (m_DashEffectTimer < 0.046f) { + if (m_DashEffectTimer < 0.075f) { return; } m_DashEffectTimer = 0.f; @@ -89,6 +89,13 @@ void PlayerMovementSystem::Update(double dt) for (auto& cAnim : dashEffect.ChildrenWithComponent("Animation")) { cAnim["Animation"]["Play"] = false; } + for (auto& cModel : dashEffect.ChildrenWithComponent("Model")) { + Entity.AttachComponent("Lifetime"); + dashEffect.AttachComponent("Fade"); + dashEffect["Fade"]["Loop"] = false; + dashEffect["Fade"]["FadeTime"] = 0.5; + dashEffect["Fade"]["Time"] = (double)dashEffect["Fade"]["FadeTime"]; + } dashEffect.AttachComponent("Lifetime"); dashEffect.AttachComponent("Fade"); dashEffect["Fade"]["Loop"] = false; From be91fc50054ccb9608b65b92d83f75df98bbd930 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Sun, 13 Mar 2016 23:23:36 +0100 Subject: [PATCH 3/4] WIP dash effect fade weapon 2. --- src/Game/Systems/PlayerMovementSystem.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 74a8de7e..71954a8f 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -90,11 +90,12 @@ void PlayerMovementSystem::Update(double dt) cAnim["Animation"]["Play"] = false; } for (auto& cModel : dashEffect.ChildrenWithComponent("Model")) { - Entity.AttachComponent("Lifetime"); - dashEffect.AttachComponent("Fade"); - dashEffect["Fade"]["Loop"] = false; - dashEffect["Fade"]["FadeTime"] = 0.5; - dashEffect["Fade"]["Time"] = (double)dashEffect["Fade"]["FadeTime"]; + EntityWrapper e(m_World, cModel.ID); + e.AttachComponent("Lifetime"); + e.AttachComponent("Fade"); + e["Fade"]["Loop"] = false; + e["Fade"]["FadeTime"] = 0.5; + e["Fade"]["Time"] = (double)dashEffect["Fade"]["FadeTime"]; } dashEffect.AttachComponent("Lifetime"); dashEffect.AttachComponent("Fade"); From 12d0c68fbf5e3c84a8997306cf4ffd7841d1488c Mon Sep 17 00:00:00 2001 From: William Moberg Date: Sun, 13 Mar 2016 23:57:47 +0100 Subject: [PATCH 4/4] Weapon should fade on dash effect afterimage. --- src/Game/Systems/PlayerMovementSystem.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 71954a8f..d2a8594a 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -83,26 +83,26 @@ void PlayerMovementSystem::Update(double dt) if (!playerModel.HasComponent("Model")) { continue; } - auto playerEntityModel = playerModel["Model"]; EntityWrapper dashEffect = playerModel.Clone(); - playerEntityModel.Copy(dashEffect["Model"]); for (auto& cAnim : dashEffect.ChildrenWithComponent("Animation")) { cAnim["Animation"]["Play"] = false; } + const double fadeTime = 0.5f; for (auto& cModel : dashEffect.ChildrenWithComponent("Model")) { EntityWrapper e(m_World, cModel.ID); e.AttachComponent("Lifetime"); e.AttachComponent("Fade"); e["Fade"]["Loop"] = false; - e["Fade"]["FadeTime"] = 0.5; - e["Fade"]["Time"] = (double)dashEffect["Fade"]["FadeTime"]; + e["Fade"]["FadeTime"] = fadeTime; + e["Fade"]["Time"] = fadeTime; + e["Lifetime"]["Lifetime"] = fadeTime; } dashEffect.AttachComponent("Lifetime"); dashEffect.AttachComponent("Fade"); dashEffect["Fade"]["Loop"] = false; - dashEffect["Fade"]["FadeTime"] = 0.5; - dashEffect["Fade"]["Time"] = (double)dashEffect["Fade"]["FadeTime"]; - dashEffect["Lifetime"]["Lifetime"] = (double)dashEffect["Fade"]["FadeTime"]; + dashEffect["Fade"]["FadeTime"] = fadeTime; + dashEffect["Fade"]["Time"] = fadeTime; + dashEffect["Lifetime"]["Lifetime"] = fadeTime; dashEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"]; dashEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"]; }