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"];