From bd59cd4108b14acaa52a684722d6279bf8f4da33 Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Thu, 15 Oct 2015 15:08:05 +0200 Subject: [PATCH] Implimented the basis for Kraken encounter. --- include/Core/Engine.h | 6 ++ include/Game/CKraken.h | 12 ++-- include/Game/EKrakenAppear.h | 26 +++++++++ include/Game/KrakenSystem.h | 14 +++++ include/Game/LevelSystem.h | 6 +- src/game/Game/KrakenSystem.cpp | 42 ++++++++++++++ src/game/Game/LevelSystem.cpp | 91 +++++++++++++++++++++--------- src/game/Game/TravellingSystem.cpp | 1 - 8 files changed, 164 insertions(+), 34 deletions(-) create mode 100644 include/Game/EKrakenAppear.h diff --git a/include/Core/Engine.h b/include/Core/Engine.h index b397501..1f61c0a 100755 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -48,6 +48,7 @@ #include "Game/CProjectile.h" #include "Game/CBrick.h" #include "Game/CWall.h" +#include "Game/CKraken.h" #include "Game/CBackground.h" #include "Game/CTravels.h" #include "Game/CStickyAim.h" @@ -56,6 +57,7 @@ #include "Game/TravellingSystem.h" #include "Game/LifebuoySystem.h" #include "Game/ProjectileSystem.h" +#include "Game/KrakenSystem.h" #include "Game/Bricks/CPowerUpBrick.h" #include "Game/BrickComponents.h" @@ -128,6 +130,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(); @@ -165,6 +168,9 @@ public: m_World->SystemFactory.Register( [this]() { return new Systems::TravellingSystem(m_World.get(), m_EventBroker); }); m_World->AddSystem(); + m_World->SystemFactory.Register( + [this]() { return new Systems::KrakenSystem(m_World.get(), m_EventBroker); }); + m_World->AddSystem(); m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); diff --git a/include/Game/CKraken.h b/include/Game/CKraken.h index aeca335..48ac112 100644 --- a/include/Game/CKraken.h +++ b/include/Game/CKraken.h @@ -1,9 +1,9 @@ // -// Created by Adniklastrator on 2015-09-15. +// Created by Adniklastrator on 2015-10-15. // -#ifndef DAYDREAM_CLIFE_H -#define DAYDREAM_CLIFE_H +#ifndef DAYDREAM_CKRAKEN_H +#define DAYDREAM_CKRAKEN_H #include "Core/Component.h" @@ -13,9 +13,9 @@ namespace dd namespace Components { -struct Life : Component { +struct Kraken : Component { - int Number = 0; + int Health = 10; }; @@ -23,4 +23,4 @@ struct Life : Component { } -#endif //DAYDREAM_CLIFE_H +#endif //DAYDREAM_CKRAKEN_H diff --git a/include/Game/EKrakenAppear.h b/include/Game/EKrakenAppear.h new file mode 100644 index 0000000..b2ce91b --- /dev/null +++ b/include/Game/EKrakenAppear.h @@ -0,0 +1,26 @@ +// +// Created by Adniklastrator on 2015-10-15. +// + +#ifndef DAYDREAM_EKRAKENAPPEAR_H +#define DAYDREAM_EKRAKENAPPEAR_H + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Events +{ + +struct KrakenAppear : Event +{ + int Health; + glm::vec3 Position; +}; + +} + +} + +#endif //DAYDREAM_EKRAKENAPPEAR_H diff --git a/include/Game/KrakenSystem.h b/include/Game/KrakenSystem.h index 945a26e..a94aa38 100644 --- a/include/Game/KrakenSystem.h +++ b/include/Game/KrakenSystem.h @@ -11,7 +11,16 @@ #include "Core/CTemplate.h" #include "Core/EventBroker.h" #include "Core/World.h" +#include "Rendering/CModel.h" +#include "Physics/CRectangleShape.h" +#include "Physics/CCircleShape.h" +#include "Physics/CPhysics.h" #include "Game/EPause.h" +#include "Game/EKrakenAppear.h" +#include "Game/EKrakenAttack.h" +#include "Game/CTravels.h" +#include "Game/CKraken.h" +#include "Sound/CCollisionSound.h" //#include "Core/Camera.h" Camera Component @@ -37,9 +46,14 @@ public: void SetPause(const bool& pause) { m_Pause = pause; } private: bool m_Pause = false; + EntityID m_KrakenTemplate; dd::EventRelay m_EPause; + dd::EventRelay m_EKrakenAppear; + dd::EventRelay m_EKrakenAttack; bool OnPause(const dd::Events::Pause &event); + bool OnKrakenAppear(const dd::Events::KrakenAppear &event); + bool OnKrakenAttack(const dd::Events::KrakenAttack &event); }; } diff --git a/include/Game/LevelSystem.h b/include/Game/LevelSystem.h index f5d6fe5..08a8aca 100755 --- a/include/Game/LevelSystem.h +++ b/include/Game/LevelSystem.h @@ -49,6 +49,8 @@ #include "Game/ECreatePowerUp.h" #include "Game/EPowerUpTaken.h" +#include "Game/EKrakenAppear.h" + #include "Physics/CPhysics.h" #include "Physics/CCircleShape.h" #include "Physics/CRectangleShape.h" @@ -133,7 +135,7 @@ private: bool m_Initialized = false; bool m_Pause = false; int m_LooseBricks = 0; - int m_CurrentCluster = 1; + int m_CurrentCluster = 0; int m_CurrentLevel = 1; int m_MultiBalls = 0; int m_PowerUps = 0; @@ -153,6 +155,8 @@ private: const int InkBlasterBrick = 5; const int KrakenAttackBrick = 6; + const int Kraken = 100; + EntityID m_BrickTemplate; std::array m_Bricks; diff --git a/src/game/Game/KrakenSystem.cpp b/src/game/Game/KrakenSystem.cpp index fb67435..0fe0614 100644 --- a/src/game/Game/KrakenSystem.cpp +++ b/src/game/Game/KrakenSystem.cpp @@ -8,6 +8,33 @@ void dd::Systems::KrakenSystem::Initialize() { EVENT_SUBSCRIBE_MEMBER(m_EPause, &KrakenSystem::OnPause); + EVENT_SUBSCRIBE_MEMBER(m_EKrakenAppear, &KrakenSystem::OnKrakenAppear); + EVENT_SUBSCRIBE_MEMBER(m_EKrakenAttack, &KrakenSystem::OnKrakenAttack); + + EntityID ent = m_World->CreateEntity(); + auto transform = m_World->AddComponent(ent); + auto model = m_World->AddComponent(ent); + std::shared_ptr cCircle = m_World->AddComponent(ent); + cCircle->Radius = 2; + std::shared_ptr cPhys = m_World->AddComponent(ent); + std::shared_ptr cTemplate = m_World->AddComponent(ent); + + auto travels = m_World->AddComponent(ent); + travels->CurrentlyTraveling = false; + + cPhys->CollisionType = CollisionType::Type::Static; + cPhys->GravityScale = 0.f; + cPhys->Category = CollisionLayer::Type::Brick; + cPhys->Mask = static_cast(CollisionLayer::Type::Ball | CollisionLayer::Type::Projectile | CollisionLayer::Type::Wall | CollisionLayer::LifeBuoy); + + model->ModelFile = "Models/Test/Ball/Sid.obj"; + transform->Position = glm::vec3(50, 50, -10); + //sound + auto collisionSound = m_World->AddComponent(ent); + collisionSound->FilePath = "Sounds/Brick/shortbrickbreak.wav"; + m_World->CommitEntity(ent); + + m_KrakenTemplate = ent; InitializeObjects(); } @@ -34,3 +61,18 @@ bool dd::Systems::KrakenSystem::OnPause(const dd::Events::Pause &event) } return true; } + +bool dd::Systems::KrakenSystem::OnKrakenAppear(const dd::Events::KrakenAppear &event) +{ + auto ent = m_World->CloneEntity(m_KrakenTemplate); + m_World->RemoveComponent(ent); + auto transform = m_World->GetComponent(ent); + transform->Position = event.Position; + return true; +} + +bool dd::Systems::KrakenSystem::OnKrakenAttack(const dd::Events::KrakenAttack &event) +{ + + return true; +} diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index bfbf654..9f93bfa 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -400,6 +400,11 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe auto transform = m_World->GetComponent(brick); auto cBrick = m_World->GetComponent(brick); auto model = m_World->GetComponent(brick); + + float x = line * spacesBetweenBricks.x; + float y = row * spacesBetweenBricks.y; + transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y + aboveLevel, -10.f); + if (typeInt == StandardBrick) { cBrick->Type = StandardBrick; auto type = m_World->AddComponent(brick); @@ -425,12 +430,15 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe cBrick->Type = KrakenAttackBrick; auto type = m_World->AddComponent(brick); model->Color = glm::vec4(0.f, 0.5f, 1.0f, .0f); + } else if (typeInt == Kraken) { + Events::KrakenAppear e; + e.Position = transform->Position; + e.Health = 10; + EventBroker->Publish(e); + m_World->RemoveEntity(brick); + return; } - - float x = line * spacesBetweenBricks.x; - float y = row * spacesBetweenBricks.y; - transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y + aboveLevel, -10.f); cBrick->Score = 10 * num; return; } @@ -700,6 +708,8 @@ void dd::Systems::LevelSystem::GetNextLevel() // 5 is ink blaster brick. // 6 is kraken attack brick. + // 100 is KRAKEN! + // wolor array determines the color of standard bricks. // w is white. // r is red. @@ -733,25 +743,8 @@ void dd::Systems::LevelSystem::GetNextLevel() glm::vec4 p4 = glm::vec4(125.f / 255.f, 0.f / 255.f, 147.f / 255.f, 1.f); - - if (m_CurrentCluster == 0) { if (m_CurrentLevel == 1) { - level = - {0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0}; - color = - {w, w, w, w, w, w, w, - w, w, w, w, w, w, w, - w, w, w, w, w, w, w, - w, w, w, w, w, w, w, - w, w, w, w, w, w, w, - w, w, w, w, w, w, w}; - } else if (m_CurrentLevel == 2) { level = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -766,7 +759,7 @@ void dd::Systems::LevelSystem::GetNextLevel() w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w}; - } else if (m_CurrentLevel == 3) { + } else if (m_CurrentLevel == 2) { level = {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, @@ -781,7 +774,7 @@ void dd::Systems::LevelSystem::GetNextLevel() w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w}; - } else if (m_CurrentLevel == 4) { + } else if (m_CurrentLevel == 3) { level = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -796,7 +789,7 @@ void dd::Systems::LevelSystem::GetNextLevel() w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w}; - } else if (m_CurrentLevel == 5) { + } else if (m_CurrentLevel == 4) { level = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -811,7 +804,37 @@ void dd::Systems::LevelSystem::GetNextLevel() w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w}; - } + } else if (m_CurrentLevel == 5) { + level = + {0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 100, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0}; + color = + {w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w}; + } else if (m_CurrentLevel == 6) { + level = + {0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0}; + color = + {w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w}; + } } else if (m_CurrentCluster == 1) { if (m_CurrentLevel == 1) { level = @@ -888,7 +911,23 @@ void dd::Systems::LevelSystem::GetNextLevel() w, br, w, g, w, lb1, w, y, w, y, d, b, w, b, w, br, w, w, w, lb1, w}; - } + } + else if (m_CurrentLevel == 6) { + level = + {0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 100, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0}; + color = + {w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w, + w, w, w, w, w, w, w}; + } } else if (m_CurrentCluster == 3) { } diff --git a/src/game/Game/TravellingSystem.cpp b/src/game/Game/TravellingSystem.cpp index 3e488d9..91377c3 100644 --- a/src/game/Game/TravellingSystem.cpp +++ b/src/game/Game/TravellingSystem.cpp @@ -52,7 +52,6 @@ void dd::Systems::TravellingSystem::UpdateEntity(double dt, EntityID entity, Ent float yValue = position.y; // A negative value between -34.6 and -22.6; yValue += 22.6; // A positive value between -12 and 0. The distance it should travel from 34.6; background->distanceLeftToCorrectTravelPosition = yValue; - std::cout << "This happened." << std::endl; } else { m_World->RemoveEntity(entity); return;