Fixed dash effect to be supported with the new animations using Fade components.

Added bool Loop field in Fade component.
This commit is contained in:
William Moberg
2016-03-13 22:49:24 +01:00
parent 148d60f8f8
commit e4145cf292
7 changed files with 69 additions and 41 deletions
@@ -32,6 +32,8 @@ private:
glm::vec3 m_LastPosition = glm::vec3(); glm::vec3 m_LastPosition = glm::vec3();
// Used to track afterimages for sprint effect. // Used to track afterimages for sprint effect.
float m_SprintEffectTimer; float m_SprintEffectTimer;
// Used to track afterimages for dash effect.
float m_DashEffectTimer;
// The logic for making the sound play when player is moving // The logic for making the sound play when player is moving
void playerStep(double dt, EntityWrapper player); void playerStep(double dt, EntityWrapper player);
// Spawn a hexagon at origin of an Entity // Spawn a hexagon at origin of an Entity
+1 -1
View File
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<BoostAssault xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BoostAssault.xsd"> <BoostAssault xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BoostAssault.xsd">
<StrengthOfEffect>2</StrengthOfEffect> <StrengthOfEffect>1.35</StrengthOfEffect>
</BoostAssault> </BoostAssault>
+1
View File
@@ -3,5 +3,6 @@
<FadeTime>1</FadeTime> <FadeTime>1</FadeTime>
<Time>0</Time> <Time>0</Time>
<Out>true</Out> <Out>true</Out>
<Loop>true</Loop>
<Reverse>false</Reverse> <Reverse>false</Reverse>
</Fade> </Fade>
+3
View File
@@ -11,6 +11,9 @@
<xs:element name="Out" type="t:bool" minOccurs="0"> <xs:element name="Out" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>If the entity should fade out or in.</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>If the entity should fade out or in.</xs:documentation></xs:annotation>
</xs:element> </xs:element>
<xs:element name="Loop" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>If the effect should loop when it is done.</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Reverse" type="t:bool" minOccurs="0"> <xs:element name="Reverse" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>If the entity should reverse the fade after finishing, this will double the speed.</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>If the entity should reverse the fade after finishing, this will double the speed.</xs:documentation></xs:annotation>
</xs:element> </xs:element>
-13
View File
@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="DashEffect" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Lifetime>
<Lifetime>0.5</Lifetime>
</c:Lifetime>
<c:Transform/>
</Components>
<Children/>
</Entity>
+2 -2
View File
@@ -24,14 +24,14 @@ void FadeSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cFade,
currentTime += dTime; currentTime += dTime;
if(currentTime > fadeTime) { if(currentTime > fadeTime) {
currentTime = 0.0; currentTime = 0.0 + fadeTime * (bool)cFade["Loop"];
if ((bool)cFade["Reverse"]) { if ((bool)cFade["Reverse"]) {
(Field<bool>)cFade["Out"] = !(bool)cFade["Out"]; (Field<bool>)cFade["Out"] = !(bool)cFade["Out"];
currentTime = fadeTime; currentTime = fadeTime;
} }
} }
if(currentTime < 0.0) { if(currentTime < 0.0) {
currentTime = fadeTime; currentTime = fadeTime * (bool)cFade["Loop"];
if ((bool)cFade["Reverse"]) { if ((bool)cFade["Reverse"]) {
(Field<bool>)cFade["Out"] = !(bool)cFade["Out"]; (Field<bool>)cFade["Out"] = !(bool)cFade["Out"];
currentTime = 0.0; currentTime = 0.0;
+60 -25
View File
@@ -3,6 +3,7 @@
PlayerMovementSystem::PlayerMovementSystem(SystemParams params) PlayerMovementSystem::PlayerMovementSystem(SystemParams params)
: System(params) : System(params)
, m_SprintEffectTimer(0.f) , m_SprintEffectTimer(0.f)
, m_DashEffectTimer(0.f)
{ {
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned);
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &PlayerMovementSystem::OnDoubleJump); EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &PlayerMovementSystem::OnDoubleJump);
@@ -24,23 +25,57 @@ void PlayerMovementSystem::Update(double dt)
if (LocalPlayer.Valid()){ if (LocalPlayer.Valid()){
updateVelocity(LocalPlayer, dt); updateVelocity(LocalPlayer, dt);
} }
//m_SprintEffectTimer += dt;
//if (m_SprintEffectTimer < 0.016f) {
m_SprintEffectTimer += dt; // return;
if (m_SprintEffectTimer < 0.016f) { //}
//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<EntityFile>("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<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"];
// }
//}
m_DashEffectTimer += dt;
if (m_DashEffectTimer < 0.046f) {
return; return;
} }
m_SprintEffectTimer = 0.f; m_DashEffectTimer = 0.f;
auto pool = m_World->GetComponents("SprintAbility"); auto pool = m_World->GetComponents("DashAbility");
if (pool == nullptr) { if (pool == nullptr) {
return; return;
} }
for (auto cSprint : *pool) { for (auto cDash : *pool) {
if (cSprint.EntityID != LocalPlayer.ID && (bool)cSprint["Active"]) { if (cDash.EntityID != LocalPlayer.ID && (double)cDash["CoolDownMaxTimer"] - (double)cDash["CoolDownTimer"] < 0.5) {
// Spawn one afterimage for each player that sprints. // Spawn one afterimage for each player that Dashes.
EntityWrapper player(m_World, cSprint.EntityID); EntityWrapper player(m_World, cDash.EntityID);
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/SprintEffect.xml");
EntityWrapper sprintEffect = entityFile->MergeInto(m_World);
auto playerModel = player.FirstChildByName("PlayerModel"); auto playerModel = player.FirstChildByName("PlayerModel");
if (!playerModel.Valid()) { if (!playerModel.Valid()) {
continue; continue;
@@ -48,20 +83,20 @@ void PlayerMovementSystem::Update(double dt)
if (!playerModel.HasComponent("Model")) { if (!playerModel.HasComponent("Model")) {
continue; continue;
} }
if (!playerModel.HasComponent("Animation")) {
continue;
}
auto playerEntityModel = playerModel["Model"]; auto playerEntityModel = playerModel["Model"];
auto playerEntityAnimation = playerModel["Animation"]; EntityWrapper dashEffect = playerModel.Clone();
playerEntityModel.Copy(sprintEffect["Model"]); playerEntityModel.Copy(dashEffect["Model"]);
playerEntityAnimation.Copy(sprintEffect["Animation"]); for (auto& cAnim : dashEffect.ChildrenWithComponent("Animation")) {
sprintEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"]; cAnim["Animation"]["Play"] = false;
((Field<glm::vec4>)sprintEffect["ExplosionEffect"]["EndColor"]).w(0.f); }
sprintEffect["Animation"]["Speed1"] = 0.0; dashEffect.AttachComponent("Lifetime");
sprintEffect["Animation"]["Speed2"] = 0.0; dashEffect.AttachComponent("Fade");
sprintEffect["Animation"]["Speed3"] = 0.0; dashEffect["Fade"]["Loop"] = false;
sprintEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"]; dashEffect["Fade"]["FadeTime"] = 0.5;
sprintEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"]; 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"];
} }
} }
} }