From 3e10d75d7572e5b8444f066ba24abb04ef673e8b Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 22 Oct 2015 17:01:14 +0200 Subject: [PATCH 1/2] Animations now pause correctly when not looping --- src/game/Rendering/AnimationSystem.cpp | 19 +++++++++---------- src/game/Rendering/Skeleton.cpp | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/game/Rendering/AnimationSystem.cpp b/src/game/Rendering/AnimationSystem.cpp index 8a44ebb..942c807 100644 --- a/src/game/Rendering/AnimationSystem.cpp +++ b/src/game/Rendering/AnimationSystem.cpp @@ -35,17 +35,16 @@ void dd::Systems::AnimationSystem::Update(double dt) if (animationComponent->Speed != 0.0) { double nextTime = animationComponent->Time + animationComponent->Speed * dt; - if (glm::abs(nextTime) > animation->Duration) { - if (!animationComponent->Loop) { - animationComponent->Time = glm::sign(nextTime) * animation->Duration; - animationComponent->Speed = 0.0; - LOG_DEBUG("Animation \"%s\" on Entity %i finished.", animationComponent->Name.c_str(), ent); - Events::AnimationComplete e; - e.Entity = ent; - e.Animation = animationComponent->Name; - } + if (!animationComponent->Loop && glm::abs(nextTime) > animation->Duration) { + animationComponent->Time = glm::sign(nextTime) * animation->Duration; + animationComponent->Speed = 0.0; + LOG_DEBUG("Animation \"%s\" on Entity %i finished.", animationComponent->Name.c_str(), ent); + Events::AnimationComplete e; + e.Entity = ent; + e.Animation = animationComponent->Name; + } else { + animationComponent->Time = nextTime; } - animationComponent->Time = nextTime; } } } diff --git a/src/game/Rendering/Skeleton.cpp b/src/game/Rendering/Skeleton.cpp index d68d59a..319bfd4 100644 --- a/src/game/Rendering/Skeleton.cpp +++ b/src/game/Rendering/Skeleton.cpp @@ -69,7 +69,7 @@ std::vector dd::Skeleton::GetFrameBones(const Animation& animation, d int currentKeyframeIndex = GetKeyframe(animation, time); const Animation::Keyframe& currentFrame = animation.Keyframes[currentKeyframeIndex]; - const Animation::Keyframe& nextFrame = animation.Keyframes[currentKeyframeIndex + 1]; + const Animation::Keyframe& nextFrame = animation.Keyframes[(currentKeyframeIndex + 1) % animation.Keyframes.size()]; float alpha = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); //auto animationFrame = Animations[""].Keyframes[frame]; @@ -149,7 +149,7 @@ int dd::Skeleton::GetKeyframe(const Animation& animation, double time) { if (time < 0) time = 0; - if (time > animation.Duration) + if (time >= animation.Duration) return animation.Keyframes.size() - 1; for (int keyframe = 0; keyframe < animation.Keyframes.size(); ++keyframe) { From d1946d46e24c556443f1e5232ff24e3702adc0ed Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 22 Oct 2015 17:01:21 +0200 Subject: [PATCH 2/2] Kraken arm animations! --- include/Game/PadSystem.h | 4 +-- src/game/Game/PadSystem.cpp | 71 +++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/include/Game/PadSystem.h b/include/Game/PadSystem.h index 0e9f9cd..5cece41 100755 --- a/include/Game/PadSystem.h +++ b/include/Game/PadSystem.h @@ -107,8 +107,8 @@ private: float m_Edge = 2.8f; float m_PadOriginalHeight = -4.8; float m_PadHeight = m_PadOriginalHeight; - EntityID m_KrakenArm = NULL; - EntityID m_KrakenArmHitbox = NULL; + EntityID m_KrakenArm = 0; + EntityID m_KrakenArmHitbox = 0; float m_PadRiseSpeed = 0.2; Components::Transform* m_Transform = nullptr; Components::Pad* m_Pad = nullptr; diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp index 3b3048c..3277007 100755 --- a/src/game/Game/PadSystem.cpp +++ b/src/game/Game/PadSystem.cpp @@ -59,6 +59,9 @@ void dd::Systems::PadSystem::Initialize() m_World->CommitEntity(ent); SetEdge(3.2 - (ctransform->Scale.x / 2)); + SetEntity(ent); + SetTransform(m_World->GetComponent(Entity())); + SetPad(m_World->GetComponent(Entity())); } //Stick @@ -77,18 +80,31 @@ void dd::Systems::PadSystem::Initialize() m_StickTransform = transform; m_StickyAim = sticky; - /*{ - auto entChild = m_World->CreateEntity(ent); - std::shared_ptr transform = m_World->AddComponent(entChild); - transform->Position = glm::vec3(0.f, 12.5f, 0.f); + /*{ + auto entChild = m_World->CreateEntity(ent); + std::shared_ptr transform = m_World->AddComponent(entChild); + transform->Position = glm::vec3(0.f, 12.5f, 0.f); - transform->Scale = glm::vec3(0.1f, 25.f, 0.1f); - std::shared_ptr sprite = m_World->AddComponent(entChild); - sprite->SpriteFile = "Models/Brick/White.png"; - sprite->Color = glm::vec4(0.f, 0.5f, 0.f, 0.5f); + transform->Scale = glm::vec3(0.1f, 25.f, 0.1f); + std::shared_ptr sprite = m_World->AddComponent(entChild); + sprite->SpriteFile = "Models/Brick/White.png"; + sprite->Color = glm::vec4(0.f, 0.5f, 0.f, 0.5f); }*/ } + // Kraken arm + { + m_KrakenArm = m_World->CreateEntity(Entity()); + auto transform = m_World->AddComponent(m_KrakenArm); + transform->Position = glm::vec3(1.f, -3.0f, 0.f); + auto model = m_World->AddComponent(m_KrakenArm); + model->ModelFile = "Models/Kraken/Arm.dae"; + auto animation = m_World->AddComponent(m_KrakenArm); + animation->Speed = 0.0f; + animation->Loop = false; + m_World->CommitEntity(m_KrakenArm); + } + m_ResetBall = true; } @@ -133,17 +149,6 @@ void dd::Systems::PadSystem::Update(double dt) return; } - if (Entity() == 0) { - for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) { - if (m_World->GetProperty(it->first, "Name") == "Pad") { - SetEntity(it->first); - SetTransform(m_World->GetComponent(Entity())); - SetPad(m_World->GetComponent(Entity())); - break; - } - } - } - if (m_KrakenAttack) { m_KrakenCharge -= m_KrakenStrength * dt; if (m_KrakenCharge < 0) { @@ -476,18 +481,10 @@ bool dd::Systems::PadSystem::OnKrakenAttack(const dd::Events::KrakenAttack &even transform->Velocity = glm::vec3(0, 0, 0); acceleration = glm::vec3(0, 0, 0); - LOG_INFO("Kraken arm duuude"); - if (!m_KrakenArm){ - LOG_INFO("InKrakenArmDuuude"); - m_KrakenArm = m_World->CreateEntity(Entity()); - auto transform = m_World->AddComponent(m_KrakenArm); - transform->Position = glm::vec3(1.f, -3.0f, 0.f); - auto model = m_World->AddComponent(m_KrakenArm); - model->ModelFile = "Models/Kraken/Arm.dae"; - auto animation = m_World->AddComponent(m_KrakenArm); - animation->Speed = 1.0f; - animation->Loop = false; - m_World->CommitEntity(m_KrakenArm); + if (m_KrakenArmHitbox == 0) { + auto animation = m_World->GetComponent(m_KrakenArm); + animation->Time = 0.0; + animation->Speed = 1.0; m_KrakenArmHitbox = m_World->CreateEntity(); auto hb_transform = m_World->AddComponent(m_KrakenArmHitbox); @@ -525,10 +522,14 @@ bool dd::Systems::PadSystem::OnKrakenAttackEnd(const dd::Events::KrakenAttackEnd m_KrakenStrength = 0; m_PlayerStrength = 0; - m_World->RemoveEntity(m_KrakenArm); - m_World->RemoveEntity(m_KrakenArmHitbox); - m_KrakenArm = NULL; - m_KrakenArmHitbox = NULL; + //m_World->RemoveEntity(m_KrakenArm); + + auto animation = m_World->GetComponent(m_KrakenArm); + animation->Time = 0.0; + animation->Speed = -1.5; + m_World->RemoveEntity(m_KrakenArmHitbox); + //m_KrakenArm = NULL; + m_KrakenArmHitbox = 0; return true; }