diff --git a/include/Core/Engine.h b/include/Core/Engine.h index 6c7201f..807fccd 100755 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -48,12 +48,14 @@ #include "Game/CLifebuoy.h" #include "Game/CProjectile.h" #include "Game/CBrick.h" +#include "Game/CBrickPart.h" #include "Game/CWall.h" #include "Game/CKraken.h" #include "Game/CBackground.h" #include "Game/CTravels.h" #include "Game/CStickyAim.h" #include "Game/BallSystem.h" +#include "Game/LifeSystem.h" #include "Game/HitLagSystem.h" #include "Game/TravellingSystem.h" #include "Game/LifebuoySystem.h" @@ -144,6 +146,7 @@ public: m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); @@ -197,6 +200,9 @@ public: m_World->SystemFactory.Register( [this]() { return new Systems::WaterSystem(m_World.get(), m_EventBroker); }); m_World->AddSystem(); + m_World->SystemFactory.Register( + [this]() { return new Systems::LifeSystem(m_World.get(), m_EventBroker); }); + m_World->AddSystem(); m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); @@ -364,13 +370,11 @@ public: job.ModelMatrix = modelMatrix * model->m_Matrix; job.Color = modelComponent->Color; - if (model->m_Skeleton != nullptr) { + if (model->m_Skeleton != nullptr && animationComponent != nullptr) { job.Skeleton = model->m_Skeleton; - if (animationComponent != nullptr) { - job.AnimationName = animationComponent->Name; - job.AnimationTime = animationComponent->Time; - job.NoRootMotion = animationComponent->NoRootMotion; - } + job.AnimationName = animationComponent->Name; + job.AnimationTime = animationComponent->Time; + job.NoRootMotion = animationComponent->NoRootMotion; } m_RendererQueue.Deferred.Add(job); diff --git a/include/Game/BallSystem.h b/include/Game/BallSystem.h index f40ce54..eb159db 100644 --- a/include/Game/BallSystem.h +++ b/include/Game/BallSystem.h @@ -1,6 +1,8 @@ #ifndef DAYDREAM_BALLSYSTEM_H #define DAYDREAM_BALLSYSTEM_H +#include + #include "Core/System.h" #include "Core/World.h" #include "Core/EventBroker.h" @@ -8,14 +10,17 @@ #include "Core/CTemplate.h" #include "Core/ResourceManager.h" #include "Core/ConfigFile.h" + #include "Physics/CPhysics.h" #include "Physics/CCircleShape.h" #include "Physics/CRectangleShape.h" #include "Physics/EContact.h" + #include "Rendering/CModel.h" #include "Rendering/CSprite.h" #include "Rendering/CPointLight.h" #include "Rendering/CAnimation.h" + #include "Game/CBall.h" #include "Game/CPowerUp.h" #include "Game/CLife.h" @@ -30,6 +35,8 @@ #include "Game/EStickyAttachedToPad.h" #include "Game/EInkBlaster.h" #include "Game/EInkBlasterOver.h" +#include "Game/EKrakenAttack.h" +#include "Game/EKrakenAttackEnd.h" #include "Game/EStageCleared.h" #include "Game/EArrivedAtNewStage.h" #include "Game/EGameOver.h" @@ -39,6 +46,7 @@ #include "Game/EHitLag.h" #include "Game/EActionButton.h" #include "Game/ELifebuoyHit.h" + #include "Physics/ECreateParticleSequence.h" #include "Sound/CCollisionSound.h" @@ -75,7 +83,6 @@ public: void OnEntityRemoved(EntityID entity) override; EntityID CreateBall(); - void CreateLife(int); EntityID Ball() { return m_Ball; }; void SetBall(const EntityID& ball) { m_Ball = ball; } @@ -87,22 +94,18 @@ public: void SetEdgeY(const float& edgeY) { m_EdgeY = edgeY; } int& MultiBalls() { return m_MultiBalls; } void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; } - int& Lives() { return m_Lives; } - void SetLives(const int& lives) { m_Lives = lives; } - int& PastLives() { return m_PastLives; } - void SetPastLives(const int& pastLives) { m_PastLives = pastLives; } bool ReplaceBall() const { return m_ReplaceBall; } void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; } bool IsPaused() const { return m_Pause; } void SetPause(const bool& pause) { m_Pause = pause; } private: + std::mt19937 m_RandomGenerator; + float m_XMovementMultiplier = 2.f; float m_EdgeX = 3.4f; //Actually 3.2, but anyways. float m_EdgeY = 5.2f; int m_MultiBalls = 0; - int m_Lives = 3; - int m_PastLives = 3; bool m_ReplaceBall = false; bool m_Pause = false; bool m_Waiting = true; @@ -110,9 +113,12 @@ private: bool m_InkBlaster = false; bool m_InkAttached = false; bool m_InkBlockedWaiting = false; + bool m_KrakenAttack = false; + double m_KrakenCharge = 0; bool m_Restarting = false; int m_StickyCounter = 3; - bool m_GodMode = false; + + bool m_First = true; bool m_StageBlockedWaiting = false; @@ -124,13 +130,14 @@ private: std::unordered_map> m_Contacts; void ResolveContacts(); - dd::EventRelay m_ELifeLost; dd::EventRelay m_EMultiBallLost; dd::EventRelay m_EResetBall; dd::EventRelay m_EMultiBall; dd::EventRelay m_EStickyPad; dd::EventRelay m_EInkBlaster; dd::EventRelay m_EInkBlasterOver; + dd::EventRelay m_EKrakenAttack; + dd::EventRelay m_EKrakenAttackEnd; dd::EventRelay m_EPause; dd::EventRelay m_EResume; dd::EventRelay m_Contact; @@ -139,13 +146,14 @@ private: dd::EventRelay m_EArrivedAtNewStage; bool Contact(const Events::Contact &event); - bool OnLifeLost(const dd::Events::LifeLost &event); bool OnMultiBallLost(const dd::Events::MultiBallLost &event); bool OnResetBall(const dd::Events::ResetBall &event); bool OnMultiBall(const dd::Events::MultiBall &event); bool OnStickyPad(const dd::Events::StickyPad &event); bool OnInkBlaster(const dd::Events::InkBlaster &event); bool OnInkBlasterOver(const dd::Events::InkBlasterOver &event); + bool OnKrakenAttack(const dd::Events::KrakenAttack &event); + bool OnKrakenAttackEnd(const dd::Events::KrakenAttackEnd &event); bool OnPause(const dd::Events::Pause &event); bool OnResume(const dd::Events::Resume &event); bool OnActionButton(const dd::Events::ActionButton &event); diff --git a/include/Game/CBrickPart.h b/include/Game/CBrickPart.h new file mode 100644 index 0000000..ff7a532 --- /dev/null +++ b/include/Game/CBrickPart.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-10-21. +// + +#ifndef DAYDREAM_CBRICKPART_H +#define DAYDREAM_CBRICKPART_H + +#include "Core/Component.h" + +namespace dd +{ + +namespace Components +{ + +struct BrickPart : Component +{ + +}; + +} + +} + +#endif //DAYDREAM_CBRICKPART_H diff --git a/include/Game/EKrakenAttackEnd.h b/include/Game/EKrakenAttackEnd.h new file mode 100644 index 0000000..eee5889 --- /dev/null +++ b/include/Game/EKrakenAttackEnd.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-10-21. +// + +#ifndef DAYDREAM_EKRAKENATTACKEND_H +#define DAYDREAM_EKRAKENATTACKEND_H + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Events +{ + +struct KrakenAttackEnd : Event +{ + +}; + +} + +} + +#endif //DAYDREAM_EKRAKENATTACKEND_H diff --git a/include/Game/GUI/HUD.h b/include/Game/GUI/HUD.h index fa12856..49310d4 100644 --- a/include/Game/GUI/HUD.h +++ b/include/Game/GUI/HUD.h @@ -51,6 +51,7 @@ public: EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &HUD::OnGameOver); EVENT_SUBSCRIBE_MEMBER(m_ClusterClear, &HUD::OnClusterClear); EVENT_SUBSCRIBE_MEMBER(m_KrakenAttack, &HUD::OnKrakenAttack); + EVENT_SUBSCRIBE_MEMBER(m_KrakenAttackEnd, &HUD::OnKrakenAttackEnd); updateScore(); } @@ -71,6 +72,7 @@ private: EventRelay m_EGameOver; EventRelay m_ClusterClear; EventRelay m_KrakenAttack; + EventRelay m_KrakenAttackEnd; void updateScore() { @@ -122,6 +124,13 @@ private: return true; } + + bool OnKrakenAttackEnd(const Events::KrakenAttackEnd& event) + { + m_KrakenAttackSlider->Hide(); + + return true; + } }; } diff --git a/include/Game/KrakenSystem.h b/include/Game/KrakenSystem.h index 3f32cf7..12e3528 100644 --- a/include/Game/KrakenSystem.h +++ b/include/Game/KrakenSystem.h @@ -21,6 +21,8 @@ #include "Physics/ECreateParticleSequence.h" #include "Game/EPause.h" #include "Game/EResume.h" +#include "Game/EComboEvent.h" +#include "Game/EScoreEvent.h" #include "Game/EKrakenAppear.h" #include "Game/EKrakenAttack.h" #include "Game/EKrakenHit.h" @@ -29,6 +31,7 @@ #include "Game/CTravels.h" #include "Game/CKraken.h" #include "Game/CBall.h" +#include "Game/CProjectile.h" #include "Sound/CCollisionSound.h" //#include "Core/Camera.h" Camera Component diff --git a/include/Game/LevelSystem.h b/include/Game/LevelSystem.h index b93fc7b..cc5d75c 100755 --- a/include/Game/LevelSystem.h +++ b/include/Game/LevelSystem.h @@ -23,6 +23,7 @@ #include "Transform/EMove.h" #include "Game/CBrick.h" +#include "Game/CBrickPart.h" #include "Game/CBall.h" #include "Game/CLife.h" #include "Game/CWall.h" diff --git a/include/Game/LifeSystem.h b/include/Game/LifeSystem.h new file mode 100644 index 0000000..249e9ee --- /dev/null +++ b/include/Game/LifeSystem.h @@ -0,0 +1,75 @@ +// +// Created by Adniklastrator on 2015-10-22. +// + +#ifndef DAYDREAM_LIFESYSTEM_H +#define DAYDREAM_LIFESYSTEM_H + + +#include "Core/System.h" +#include "Core/CTransform.h" +#include "Core/CTemplate.h" +#include "Core/EventBroker.h" +#include "Core/World.h" + +#include "Core/ConfigFile.h" + +#include "Transform/EMove.h" +#include "Rendering/CModel.h" + +#include "Game/CLife.h" +#include "Game/EPause.h" +#include "Game/EResume.h" +#include "Game/ELifeLost.h" +#include "Game/EGameOver.h" +#include "Game/EKrakenAttackEnd.h" + + +namespace dd +{ + +namespace Systems +{ + +class LifeSystem : public System +{ +public: + LifeSystem(World* world, std::shared_ptr eventBroker) + : System(world, eventBroker) + { } + + + void Initialize() override; + void Update(double dt) override; + void UpdateEntity(double dt, EntityID entity, EntityID parent) override; + + bool IsPaused() const { return m_Pause; } + void SetPause(const bool& pause) { m_Pause = pause; } + int& Lives() { return m_Lives; } + void SetLives(const int& lives) { m_Lives = lives; } + int& PastLives() { return m_PastLives; } + void SetPastLives(const int& pastLives) { m_PastLives = pastLives; } + +private: + bool m_Pause = false; + int m_Lives = 3; + int m_PastLives = 3; + + bool m_GodMode = false; + + void CreateLife(int); + + dd::EventRelay m_EPause; + dd::EventRelay m_EResume; + dd::EventRelay m_ELifeLost; + + bool OnPause(const dd::Events::Pause &event); + bool OnResume(const dd::Events::Resume &event); + bool OnLifeLost(const dd::Events::LifeLost &event); +}; + +} + +} + +#endif //DAYDREAM_LIFESYSTEM_H diff --git a/include/Game/PadSystem.h b/include/Game/PadSystem.h index 981bda5..59badca 100755 --- a/include/Game/PadSystem.h +++ b/include/Game/PadSystem.h @@ -43,6 +43,7 @@ #include "Game/EStickyAttachedToPad.h" #include "Game/EInkBlaster.h" #include "Game/EKrakenAttack.h" +#include "Game/EKrakenAttackEnd.h" #include "Game/EPowerUpTaken.h" #include "Game/EStageCleared.h" #include "Game/EPause.h" @@ -126,6 +127,7 @@ private: dd::EventRelay m_EPause; dd::EventRelay m_EResume; dd::EventRelay m_EKrakenAttack; + dd::EventRelay m_EKrakenAttackEnd; dd::EventRelay m_EStickyPad; dd::EventRelay m_EStickyAttachedToPad; dd::EventRelay m_EActionButton; @@ -143,6 +145,7 @@ private: bool OnPause(const dd::Events::Pause &event); bool OnResume(const dd::Events::Resume &event); bool OnKrakenAttack(const dd::Events::KrakenAttack &event); + bool OnKrakenAttackEnd(const dd::Events::KrakenAttackEnd &event); bool OnStickyPad(const dd::Events::StickyPad &event); bool OnStickyAttachedToPad(const dd::Events::StickyAttachedToPad &event); bool OnActionButton(const dd::Events::ActionButton &event); diff --git a/include/Game/ProjectileSystem.h b/include/Game/ProjectileSystem.h index 9491113..41e1900 100644 --- a/include/Game/ProjectileSystem.h +++ b/include/Game/ProjectileSystem.h @@ -19,6 +19,8 @@ #include "Game/EResume.h" #include "Game/EInkBlaster.h" #include "Game/EInkBlasterOver.h" +#include "Game/EKrakenAttack.h" +#include "Game/EKrakenAttackEnd.h" #include "Game/EActionButton.h" #include "Game/EHitPad.h" #include "Game/CProjectile.h" @@ -52,6 +54,7 @@ private: bool m_Pause = false; bool m_InkBlaster = false; bool m_SquidLoaded = false; + bool m_KrakenAttack = false; int m_Shots = 0; float m_InkBlasterSpeed = 5; EntityID m_InkBlastTemplate; @@ -61,6 +64,8 @@ private: dd::EventRelay m_EPause; dd::EventRelay m_EResume; dd::EventRelay m_EInkBlaster; + dd::EventRelay m_EKrakenAttack; + dd::EventRelay m_EKrakenAttackEnd; dd::EventRelay m_EHitPad; dd::EventRelay m_EActionButton; @@ -68,6 +73,8 @@ private: bool OnPause(const dd::Events::Pause &event); bool OnResume(const dd::Events::Resume &event); bool OnInkBlaster(const dd::Events::InkBlaster &event); + bool OnKrakenAttack(const dd::Events::KrakenAttack &event); + bool OnKrakenAttackEnd(const dd::Events::KrakenAttackEnd &event); bool OnHitPad(const dd::Events::HitPad &event); bool OnActionButton(const dd::Events::ActionButton &event); }; diff --git a/include/Rendering/AnimationSystem.h b/include/Rendering/AnimationSystem.h index 4fe4cb8..2ce1569 100644 --- a/include/Rendering/AnimationSystem.h +++ b/include/Rendering/AnimationSystem.h @@ -4,6 +4,9 @@ #include "Core/System.h" #include "Core/World.h" #include "Rendering/CAnimation.h" +#include "Rendering/EAnimationComplete.h" +#include "Rendering/CModel.h" +#include "Rendering/Model.h" #include "Game/EPause.h" #include "Game/EResume.h" diff --git a/include/Rendering/CAnimation.h b/include/Rendering/CAnimation.h index 1b953e7..d708d55 100644 --- a/include/Rendering/CAnimation.h +++ b/include/Rendering/CAnimation.h @@ -13,6 +13,7 @@ struct Animation : Component std::string Name; double Time = 0.0; double Speed = 0.0; + bool Loop = true; bool NoRootMotion = true; }; diff --git a/include/Rendering/EAnimationComplete.h b/include/Rendering/EAnimationComplete.h new file mode 100644 index 0000000..e39ce57 --- /dev/null +++ b/include/Rendering/EAnimationComplete.h @@ -0,0 +1,21 @@ +#ifndef RENDERING_EANIMATIONCOMPLETE_H__ +#define RENDERING_EANIMATIONCOMPLETE_H__ + +#include "Core/Entity.h" +#include "Core/EventBroker.h" + +namespace dd +{ +namespace Events +{ + +struct AnimationComplete +{ + EntityID Entity; + std::string Animation; +}; + +} +} + +#endif \ No newline at end of file diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index b773370..786962b 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -12,15 +12,17 @@ void dd::Systems::BallSystem::RegisterComponents(ComponentFactory *cf) void dd::Systems::BallSystem::Initialize() { - + std::random_device rd; + m_RandomGenerator = std::mt19937(rd()); EVENT_SUBSCRIBE_MEMBER(m_Contact, &BallSystem::Contact); - EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, &BallSystem::OnLifeLost); EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &BallSystem::OnMultiBallLost); EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &BallSystem::OnResetBall); EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall); EVENT_SUBSCRIBE_MEMBER(m_EStickyPad, &BallSystem::OnStickyPad); EVENT_SUBSCRIBE_MEMBER(m_EInkBlaster, &BallSystem::OnInkBlaster); EVENT_SUBSCRIBE_MEMBER(m_EInkBlasterOver, &BallSystem::OnInkBlasterOver); + EVENT_SUBSCRIBE_MEMBER(m_EKrakenAttack, &BallSystem::OnKrakenAttack); + EVENT_SUBSCRIBE_MEMBER(m_EKrakenAttackEnd, &BallSystem::OnKrakenAttackEnd); EVENT_SUBSCRIBE_MEMBER(m_EPause, &BallSystem::OnPause); EVENT_SUBSCRIBE_MEMBER(m_EResume, &BallSystem::OnResume); EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &BallSystem::OnActionButton); @@ -35,6 +37,7 @@ void dd::Systems::BallSystem::Initialize() transform->Position = glm::vec3(-20.f, 0.26f, -10.f); transform->Scale = glm::vec3(0.3f, 0.3f, 0.3f); transform->Velocity = glm::vec3(0.f, 0.f, 0.f); + transform->Orientation = glm::quat(); auto model = m_World->AddComponent(ent); model->ModelFile = "Models/Sid/Sid.dae"; auto animation = m_World->AddComponent(ent); @@ -63,27 +66,11 @@ void dd::Systems::BallSystem::Initialize() transform2->Velocity = glm::vec3(0.0f, -10.f, 0.f); } - for (int i = 0; i < Lives(); i++) { - CreateLife(i); - } - - m_GodMode = ResourceManager::Load("Config.ini")->GetValue("Cheat.GodMode", false); + SetReplaceBall(true); } void dd::Systems::BallSystem::Update(double dt) { - if (Lives() == 0) - { - Events::GameOver e; - EventBroker->Publish(e); - - Events::Pause p; - p.Type = "All"; - EventBroker->Publish(p); - - //TODO: Make this not so ugly - SetLives(-1); - } ResolveContacts(); } @@ -126,7 +113,11 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID if (ReplaceBall()) { SetReplaceBall(false); m_Waiting = true; + std::uniform_real_distribution dist(-0.5f, 0.5f); + float random = dist(m_RandomGenerator); + ballComponent->SavedSpeed = glm::vec3(random, 1, 0.f); ballComponent->Waiting = true; + auto transform = m_World->GetComponent(entity); } if (ballComponent->Waiting) { @@ -134,12 +125,17 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID m_Restarting = false; ballComponent->Waiting = false; auto transform = m_World->GetComponent(entity); - transform->Velocity = glm::normalize(glm::vec3(0.5f, 1, 0.f)) * ballComponent->Speed; + /*std::uniform_real_distribution dist(-0.5f, 0.5f); + float random = dist(m_RandomGenerator);*/ + transform->Velocity = glm::normalize(ballComponent->SavedSpeed) * ballComponent->Speed; } else if (!ballComponent->Sticky) { auto transform = m_World->GetComponent(entity); transform->Velocity = glm::vec3(0.f, 0.f, 0.f); //transform->Position = glm::vec3(0.0f, -3.f, -10.f); - transform->Orientation = glm::quat(); + if (m_First) { + transform->Orientation = glm::quat(); + m_First = false; + } return; } } @@ -170,7 +166,7 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID m_World->RemoveEntity(entity); Events::MultiBallLost e; EventBroker->Publish(e); - } else if (Lives() == PastLives() && !m_Restarting) { + } else if (!m_Restarting) { //If we lose lives when we shouldn't, look here. Events::ResetBall be; EventBroker->Publish(be); Events::LifeLost e; @@ -197,16 +193,6 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID }*/ } - if (Lives() != PastLives()) { - auto life = m_World->GetComponent(entity); - if (life != nullptr) { - if (life->Number + 1 == PastLives()) { - m_World->RemoveEntity(entity); - SetPastLives(Lives()); - } - } - } - if (ballComponent != nullptr) { if (!ballComponent->Sticky) { @@ -433,31 +419,6 @@ EntityID dd::Systems::BallSystem::CreateBall() return ent; } -void dd::Systems::BallSystem::CreateLife(int number) -{ - auto life = m_World->CreateEntity(); - std::shared_ptr transform = m_World->AddComponent(life); - transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f); - transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f); - - std::shared_ptr lifeNr = m_World->AddComponent(life); - lifeNr->Number = number; - - auto model = m_World->AddComponent(life); - model->ModelFile = "Models/Sid/Sid.dae"; - - - m_World->CommitEntity(life); -} - -bool dd::Systems::BallSystem::OnLifeLost(const dd::Events::LifeLost &event) -{ - if (!m_GodMode){ - SetLives(Lives() - 1); - } - return true; -} - bool dd::Systems::BallSystem::OnMultiBallLost(const dd::Events::MultiBallLost &event) { SetMultiBalls(MultiBalls() - 1); @@ -531,11 +492,25 @@ bool dd::Systems::BallSystem::OnInkBlasterOver(const dd::Events::InkBlasterOver return true; } +bool dd::Systems::BallSystem::OnKrakenAttack(const dd::Events::KrakenAttack &event) +{ + m_KrakenAttack = true; + return true; +} + +bool dd::Systems::BallSystem::OnKrakenAttackEnd(const dd::Events::KrakenAttackEnd &event) +{ + m_KrakenAttack = false; + return true; +} + bool dd::Systems::BallSystem::OnActionButton(const dd::Events::ActionButton &event) { - if (!m_StageBlockedWaiting) { - if (!m_InkBlockedWaiting) { - m_Waiting = false; + if (!m_KrakenAttack) { + if (!m_StageBlockedWaiting) { + if (!m_InkBlockedWaiting) { + m_Waiting = false; + } } } return true; diff --git a/src/game/Game/KrakenSystem.cpp b/src/game/Game/KrakenSystem.cpp index 56a1dae..b15499e 100644 --- a/src/game/Game/KrakenSystem.cpp +++ b/src/game/Game/KrakenSystem.cpp @@ -95,6 +95,7 @@ void dd::Systems::KrakenSystem::UpdateEntity(double dt, EntityID entity, EntityI } break; case 2: // Grabbing + m_NumberOfActions++; kraken->CurrentAction = 5; krakenAttack.ChargeUpdate = 0; krakenAttack.KrakenStrength = 0.1; @@ -103,6 +104,7 @@ void dd::Systems::KrakenSystem::UpdateEntity(double dt, EntityID entity, EntityI break; case 3: // Brick Generating { + m_NumberOfActions++; kraken->CurrentAction = 1; Events::BrickGenerating e; e.Origin1 = glm::vec3(-5, 7, -10); @@ -185,8 +187,29 @@ bool dd::Systems::KrakenSystem::OnContact(const dd::Events::Contact &event) return false; } + auto projectile = m_World->GetComponent(otherEntitiy); + if (projectile != nullptr) { + Events::ScoreEvent es; + es.Score = 23; + Events::KrakenHit e; + e.Kraken = krakenEntity; + e.Hitter = otherEntitiy; + e.MaxHealth = kraken->MaxHealth; + e.CurrentHealth = kraken->Health; + e.NewHealth = kraken->Health - 1; + EventBroker->Publish(e); + m_World->RemoveEntity(otherEntitiy); + return true; + } auto ball = m_World->GetComponent(otherEntitiy); if (ball != nullptr) { + ball->Combo += 1; + Events::ComboEvent ec; + ec.Combo = ball->Combo; + ec.Ball = otherEntitiy; + EventBroker->Publish(ec); + Events::ScoreEvent es; + es.Score = ball->Combo * 23; Events::KrakenHit e; e.Kraken = krakenEntity; e.Hitter = otherEntitiy; @@ -195,6 +218,7 @@ bool dd::Systems::KrakenSystem::OnContact(const dd::Events::Contact &event) e.NewHealth = kraken->Health - 1; EventBroker->Publish(e); } + return true; } bool dd::Systems::KrakenSystem::OnKrakenAppear(const dd::Events::KrakenAppear &event) diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index 718d2e9..64f86cc 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -278,6 +278,15 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID } } + auto brickPart = m_World->GetComponent(entity); + if (brickPart != nullptr) { + auto transform = m_World->GetComponent(entity); + if (transform->Position.y < -10) { + m_World->RemoveEntity(entity); + return; + } + } + auto brick = m_World->GetComponent(entity); if (brick != nullptr) { auto transform = m_World->GetComponent(entity); @@ -310,6 +319,7 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID } m_LooseBricks--; m_World->RemoveEntity(entity); + return; } } @@ -909,6 +919,7 @@ bool dd::Systems::LevelSystem::OnPowerUpTaken(const dd::Events::PowerUpTaken &ev bool dd::Systems::LevelSystem::OnKrakenDefeated(const dd::Events::KrakenDefeated &event) { + m_BrickGenerating = false; SetNumberOfBricks(NumberOfBricks() - 1); m_LooseBricks--; @@ -1240,6 +1251,7 @@ void dd::Systems::LevelSystem::CreateBrokenModelPart(EntityID Parent, std::strin auto ent = m_World->CreateEntity(Parent); auto cTemplate = m_World->AddComponent(ent); auto cTransform = m_World->AddComponent(ent); + auto cBrickPart = m_World->AddComponent(ent); cTransform->Position = RelativePosition; diff --git a/src/game/Game/LifeSystem.cpp b/src/game/Game/LifeSystem.cpp new file mode 100644 index 0000000..968ed17 --- /dev/null +++ b/src/game/Game/LifeSystem.cpp @@ -0,0 +1,101 @@ +// +// Created by Adniklastrator on 2015-10-13. +// + +#include "PrecompiledHeader.h" +#include "Game/LifeSystem.h" + +void dd::Systems::LifeSystem::Initialize() +{ + EVENT_SUBSCRIBE_MEMBER(m_EPause, &LifeSystem::OnPause); + EVENT_SUBSCRIBE_MEMBER(m_EResume, &LifeSystem::OnResume); + EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, &LifeSystem::OnLifeLost); + + for (int i = 0; i < Lives(); i++) { + CreateLife(i); + } + + m_GodMode = ResourceManager::Load("Config.ini")->GetValue("Cheat.GodMode", false); +} + +void dd::Systems::LifeSystem::Update(double dt) +{ + if (m_Pause) { + return; + } + if (Lives() < 0) { + Events::KrakenAttackEnd ek; + EventBroker->Publish(ek); + + Events::GameOver e; + EventBroker->Publish(e); + + Events::Pause p; + p.Type = "All"; + EventBroker->Publish(p); + + //TODO: Make this not so ugly + SetLives(3); + } +} + +void dd::Systems::LifeSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) +{ + if (m_Pause) { + return; + } + + auto templateCheck = m_World->GetComponent(entity); + if (templateCheck != nullptr){ return; } + + if (Lives() != PastLives()) { + auto life = m_World->GetComponent(entity); + if (life != nullptr) { + if (life->Number + 1 == PastLives()) { + m_World->RemoveEntity(entity); + SetPastLives(Lives()); + } + } + } +} + +void dd::Systems::LifeSystem::CreateLife(int number) +{ + auto life = m_World->CreateEntity(); + std::shared_ptr transform = m_World->AddComponent(life); + transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f); + transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f); + + std::shared_ptr lifeNr = m_World->AddComponent(life); + lifeNr->Number = number; + + auto model = m_World->AddComponent(life); + model->ModelFile = "Models/Sid/Sid.dae"; + + m_World->CommitEntity(life); +} + +bool dd::Systems::LifeSystem::OnLifeLost(const dd::Events::LifeLost &event) +{ + if (!m_GodMode){ + SetLives(Lives() - 1); + } + return true; +} + +bool dd::Systems::LifeSystem::OnPause(const dd::Events::Pause &event) +{ + /*if (event.Type != "LifeSystem" && event.Type != "All") { + return false; + }*/ + m_Pause = true; + return true; +} +bool dd::Systems::LifeSystem::OnResume(const dd::Events::Resume &event) +{ + /*if (event.Type != "LifeSystem" && event.Type != "All") { + return false; + }*/ + m_Pause = false; + return true; +} \ No newline at end of file diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp index 5814179..4b75394 100755 --- a/src/game/Game/PadSystem.cpp +++ b/src/game/Game/PadSystem.cpp @@ -34,6 +34,7 @@ void dd::Systems::PadSystem::Initialize() EVENT_SUBSCRIBE_MEMBER(m_EPause, &PadSystem::OnPause); EVENT_SUBSCRIBE_MEMBER(m_EResume, &PadSystem::OnResume); EVENT_SUBSCRIBE_MEMBER(m_EKrakenAttack, &PadSystem::OnKrakenAttack); + EVENT_SUBSCRIBE_MEMBER(m_EKrakenAttackEnd, &PadSystem::OnKrakenAttackEnd); EVENT_SUBSCRIBE_MEMBER(m_EStickyPad, &PadSystem::OnStickyPad); EVENT_SUBSCRIBE_MEMBER(m_EStickyAttachedToPad, &PadSystem::OnStickyAttachedToPad); EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &PadSystem::OnActionButton); @@ -508,16 +509,24 @@ bool dd::Systems::PadSystem::OnKrakenAttack(const dd::Events::KrakenAttack &even SetAcceleration(acceleration); } else if (m_KrakenCharge >= 1) { m_KrakenAttack = false; - m_KrakenCharge = 0; - m_KrakenStrength = 0; - m_PlayerStrength = 0; + Events::KrakenAttackEnd e; + EventBroker->Publish(e); + } + return true; +} + +bool dd::Systems::PadSystem::OnKrakenAttackEnd(const dd::Events::KrakenAttackEnd &event) +{ + m_KrakenAttack = false; + m_KrakenCharge = 0; + m_KrakenStrength = 0; + m_PlayerStrength = 0; m_World->RemoveEntity(m_KrakenArm); m_World->RemoveEntity(m_KrakenArmHitbox); m_KrakenArm = NULL; m_KrakenArmHitbox = NULL; - } return true; } diff --git a/src/game/Game/ProjectileSystem.cpp b/src/game/Game/ProjectileSystem.cpp index eba7b43..05266e1 100644 --- a/src/game/Game/ProjectileSystem.cpp +++ b/src/game/Game/ProjectileSystem.cpp @@ -13,6 +13,8 @@ void dd::Systems::ProjectileSystem::Initialize() EVENT_SUBSCRIBE_MEMBER(m_EPause, &ProjectileSystem::OnPause); EVENT_SUBSCRIBE_MEMBER(m_EResume, &ProjectileSystem::OnResume); EVENT_SUBSCRIBE_MEMBER(m_EInkBlaster, &ProjectileSystem::OnInkBlaster); + EVENT_SUBSCRIBE_MEMBER(m_EKrakenAttack, &ProjectileSystem::OnKrakenAttack); + EVENT_SUBSCRIBE_MEMBER(m_EKrakenAttackEnd, &ProjectileSystem::OnKrakenAttackEnd); EVENT_SUBSCRIBE_MEMBER(m_EHitPad, &ProjectileSystem::OnHitPad); EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &ProjectileSystem::OnActionButton); @@ -113,34 +115,48 @@ bool dd::Systems::ProjectileSystem::OnHitPad(const dd::Events::HitPad &event) return true; } +bool dd::Systems::ProjectileSystem::OnKrakenAttack(const dd::Events::KrakenAttack &event) +{ + m_KrakenAttack = true; + return true; +} + +bool dd::Systems::ProjectileSystem::OnKrakenAttackEnd(const dd::Events::KrakenAttackEnd &event) +{ + m_KrakenAttack = false; + return true; +} + bool dd::Systems::ProjectileSystem::OnActionButton(const dd::Events::ActionButton &event) { - if (m_InkBlaster && m_SquidLoaded) { - auto ent = m_World->CloneEntity(m_InkBlastTemplate); - m_World->RemoveComponent(ent); - auto projectile = m_World->GetComponent(ent); - projectile->Speed = m_InkBlasterSpeed; - auto transform = m_World->GetComponent(ent); - transform->Position = event.Position; - transform->Velocity = glm::vec3(0, projectile->Speed, 0); - m_Shots--; - if (m_Shots <= 0) { - auto ball = m_World->GetComponent(m_AttachedSquid); - m_InkBlaster = false; - m_SquidLoaded = false; - ball->InkBlaster = false; - ball->Sticky = false; - ball->Waiting = true; - - { - Events::InkBlasterOver e; - e.Ball = m_AttachedSquid; - EventBroker->Publish(e); - } + if (!m_KrakenAttack) { + if (m_InkBlaster && m_SquidLoaded) { + auto ent = m_World->CloneEntity(m_InkBlastTemplate); + m_World->RemoveComponent(ent); + auto projectile = m_World->GetComponent(ent); + projectile->Speed = m_InkBlasterSpeed; + auto transform = m_World->GetComponent(ent); + transform->Position = event.Position; + transform->Velocity = glm::vec3(0, projectile->Speed, 0); + m_Shots--; + if (m_Shots <= 0) { + auto ball = m_World->GetComponent(m_AttachedSquid); + m_InkBlaster = false; + m_SquidLoaded = false; + ball->InkBlaster = false; + ball->Sticky = false; + ball->Waiting = true; + + { + Events::InkBlasterOver e; + e.Ball = m_AttachedSquid; + EventBroker->Publish(e); + } { Events::ActionButton e; EventBroker->Publish(e); } + } } } return true; diff --git a/src/game/Rendering/AnimationSystem.cpp b/src/game/Rendering/AnimationSystem.cpp index 35f853a..8a44ebb 100644 --- a/src/game/Rendering/AnimationSystem.cpp +++ b/src/game/Rendering/AnimationSystem.cpp @@ -24,8 +24,29 @@ void dd::Systems::AnimationSystem::Update(double dt) } for (auto& component : *animations) { - auto animation = static_cast(component.get()); - animation->Time += animation->Speed * dt; + EntityID ent = component->Entity; + auto animationComponent = static_cast(component.get()); + + // Get animation information + auto modelComponent = m_World->GetComponent(ent); + auto model = ResourceManager::Load(modelComponent->ModelFile); + auto skeleton = model->m_Skeleton; + auto animation = skeleton->GetAnimation(animationComponent->Name); + + 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; + } + } + animationComponent->Time = nextTime; + } } } diff --git a/src/game/Rendering/RawModel.cpp b/src/game/Rendering/RawModel.cpp index 46fb5df..35d7da6 100644 --- a/src/game/Rendering/RawModel.cpp +++ b/src/game/Rendering/RawModel.cpp @@ -293,6 +293,10 @@ dd::RawModel::RawModel(std::string fileName) Skeleton::Animation::Keyframe animationFrame; animationFrame.Index = keyframe; animationFrame.Time = frameTimes[keyframe] / animation->mTicksPerSecond; + // HACK: For some reason Blender likes to create a first frame that doesn't start at time 0 + if (keyframe == 0) { + animationFrame.Time = 0; + } for (auto &kv2 : kv.second) { int boneID = kv2.first; auto &property = kv2.second; diff --git a/src/game/Rendering/Skeleton.cpp b/src/game/Rendering/Skeleton.cpp index 69e9651..d68d59a 100644 --- a/src/game/Rendering/Skeleton.cpp +++ b/src/game/Rendering/Skeleton.cpp @@ -154,7 +154,7 @@ int dd::Skeleton::GetKeyframe(const Animation& animation, double time) for (int keyframe = 0; keyframe < animation.Keyframes.size(); ++keyframe) { if (animation.Keyframes[keyframe].Time > time) - return glm::max(0, keyframe - 1); // HACK: If the time is less than the first keyframe, don + return (keyframe - 1) % animation.Keyframes.size(); } return 0;