Animations in the game

This commit is contained in:
viktorljung
2015-10-23 14:35:11 +02:00
parent 67ef462a53
commit 6206859568
7 changed files with 105 additions and 61 deletions
+52 -12
View File
@@ -28,6 +28,7 @@ void dd::Systems::BallSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &BallSystem::OnActionButton);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &BallSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_EArrivedAtNewStage, &BallSystem::OnArrivedToNewStage);
EVENT_SUBSCRIBE_MEMBER(m_EAnimationComplete, &BallSystem::OnAnimationComplete);
//OctoBall
@@ -108,14 +109,30 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
/*std::uniform_real_distribution<float> dist(-0.5f, 0.5f);
float random = dist(m_RandomGenerator);*/
transform->Velocity = glm::normalize(ballComponent->SavedSpeed) * ballComponent->Speed;
auto cAnim = m_World->GetComponent<Components::Animation>(entity);
cAnim->Loop = false;
cAnim->Speed = 2.f;
cAnim->Time = 0.f;
//transform->Velocity = glm::normalize(glm::vec3(0, 1, 0)) * ballComponent->Speed;
} else if (!ballComponent->Sticky) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
//transform->Position = glm::vec3(0.0f, -3.f, -10.f);
if (m_First) {
transform->Orientation = glm::quat();
m_First = false;
} else {
auto cModel = m_World->GetComponent<Components::Model>(entity);
cModel->ModelFile = "Models/Sid/Sid_Jump.dae";
auto cAnim = m_World->GetComponent<Components::Animation>(entity);
cAnim->Speed = 0.f;
//cAnim->Time = 0.f; //Maybe not the best but it works;
if (!ballComponent->Sticky) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
//transform->Position = glm::vec3(0.0f, -3.f, -10.f);
if (m_First) {
transform->Orientation = glm::quat();
m_First = false;
}
}
return;
}
@@ -320,7 +337,7 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
m_Waiting = true;
m_InkBlockedWaiting = true;
ballComponent->Sticky = true;
ballComponent->StickyPlacement = glm::vec3(0, 0.5f, 0);
ballComponent->StickyPlacement = glm::vec3(0, 0.25f, 0);
ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed;
ballTransform->Velocity = glm::vec3(0.f, 0.f, 0.f);
}
@@ -330,7 +347,7 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
m_Waiting = true;
ballComponent->Sticky = true;
//ballComponent->StickyPlacement = ballTransform->Position - padTransform->Position;
ballComponent->StickyPlacement = glm::vec3(0, 0.5f, 0);
ballComponent->StickyPlacement = glm::vec3(0, 0.25f, 0);
ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed;
ballTransform->Velocity *= -1;
Events::StickyAttachedToPad e;
@@ -385,10 +402,7 @@ void dd::Systems::BallSystem::ResolveContacts()
auto ballComponent = m_World->GetComponent<Components::Ball>(entity);
reflectedVelocity = glm::normalize(reflectedVelocity) * ballComponent->Speed;
transform->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
m_Contacts.clear();
}
@@ -464,6 +478,14 @@ bool dd::Systems::BallSystem::OnInkBlasterOver(const dd::Events::InkBlasterOver
auto ballComponent = m_World->GetComponent<Components::Ball>(event.Ball);
auto transform = m_World->GetComponent<Components::Transform>(event.Ball);
auto cModel = m_World->GetComponent<Components::Model>(event.Ball);
cModel->ModelFile = "Models/Sid/Sid_Jump.dae";
auto cAnim = m_World->GetComponent<Components::Animation>(event.Ball);
cAnim->Speed = 2.f;
cAnim->Loop = false;
m_InkBlaster = false;
m_InkAttached = false;
m_InkBlockedWaiting = false;
@@ -510,3 +532,21 @@ bool dd::Systems::BallSystem::OnArrivedToNewStage(const dd::Events::ArrivedAtNew
return true;
}
bool dd::Systems::BallSystem::OnAnimationComplete(const dd::Events::AnimationComplete &event)
{
LOG_INFO("ANIMATION DONE");
auto model = m_World->GetComponent<Components::Model>(event.Entity);
if (model) {
if (model->ModelFile == "Models/Sid/Sid_Jump.dae") {
model->ModelFile = "Models/Sid/Sid_Flying.dae";
auto anim = m_World->GetComponent<Components::Animation>(event.Entity);
anim->Speed = 1.f;
anim->Loop = true;
anim->Time = 0.f;
}
}
return true;
}