Put all LifeStuff into a new LifeSystem. Appears to be working.
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
#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"
|
||||
@@ -199,6 +200,9 @@ public:
|
||||
m_World->SystemFactory.Register<Systems::WaterSystem>(
|
||||
[this]() { return new Systems::WaterSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::WaterSystem>();
|
||||
m_World->SystemFactory.Register<Systems::LifeSystem>(
|
||||
[this]() { return new Systems::LifeSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::LifeSystem>();
|
||||
|
||||
m_World->ComponentFactory.Register<Components::Model>();
|
||||
m_World->ComponentFactory.Register<Components::Template>();
|
||||
|
||||
@@ -10,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"
|
||||
@@ -43,6 +46,7 @@
|
||||
#include "Game/EHitLag.h"
|
||||
#include "Game/EActionButton.h"
|
||||
#include "Game/ELifebuoyHit.h"
|
||||
|
||||
#include "Physics/ECreateParticleSequence.h"
|
||||
#include "Sound/CCollisionSound.h"
|
||||
|
||||
@@ -79,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; }
|
||||
|
||||
@@ -91,10 +94,6 @@ 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; }
|
||||
@@ -107,8 +106,6 @@ private:
|
||||
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;
|
||||
@@ -120,7 +117,6 @@ private:
|
||||
double m_KrakenCharge = 0;
|
||||
bool m_Restarting = false;
|
||||
int m_StickyCounter = 3;
|
||||
bool m_GodMode = false;
|
||||
|
||||
bool m_First = true;
|
||||
|
||||
@@ -134,7 +130,6 @@ private:
|
||||
std::unordered_map<EntityID, std::list<glm::vec2>> m_Contacts;
|
||||
void ResolveContacts();
|
||||
|
||||
dd::EventRelay<BallSystem, dd::Events::LifeLost> m_ELifeLost;
|
||||
dd::EventRelay<BallSystem, dd::Events::MultiBallLost> m_EMultiBallLost;
|
||||
dd::EventRelay<BallSystem, dd::Events::ResetBall> m_EResetBall;
|
||||
dd::EventRelay<BallSystem, dd::Events::MultiBall> m_EMultiBall;
|
||||
@@ -151,7 +146,6 @@ private:
|
||||
dd::EventRelay<BallSystem, dd::Events::ArrivedAtNewStage> 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);
|
||||
|
||||
@@ -144,7 +144,7 @@ private:
|
||||
bool m_Initialized = false;
|
||||
bool m_Pause = false;
|
||||
int m_LooseBricks = 0;
|
||||
int m_CurrentCluster = 0;
|
||||
int m_CurrentCluster = 1;
|
||||
int m_CurrentLevel = 1;
|
||||
int m_MultiBalls = 0;
|
||||
int m_PowerUps = 0;
|
||||
|
||||
@@ -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<dd::EventBroker> 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<LifeSystem, dd::Events::Pause> m_EPause;
|
||||
dd::EventRelay<LifeSystem, dd::Events::Resume> m_EResume;
|
||||
dd::EventRelay<LifeSystem, dd::Events::LifeLost> 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
|
||||
@@ -15,7 +15,6 @@ 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);
|
||||
@@ -67,33 +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);
|
||||
}
|
||||
|
||||
SetReplaceBall(true);
|
||||
|
||||
m_GodMode = ResourceManager::Load<ConfigFile>("Config.ini")->GetValue<bool>("Cheat.GodMode", false);
|
||||
}
|
||||
|
||||
void dd::Systems::BallSystem::Update(double dt)
|
||||
{
|
||||
if (Lives() == 0) {
|
||||
if (m_KrakenAttack) {
|
||||
Events::KrakenAttackEnd e;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
Events::GameOver e;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
Events::Pause p;
|
||||
p.Type = "All";
|
||||
EventBroker->Publish(p);
|
||||
|
||||
//TODO: Make this not so ugly
|
||||
SetLives(-1);
|
||||
}
|
||||
ResolveContacts();
|
||||
}
|
||||
|
||||
@@ -189,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;
|
||||
@@ -216,16 +193,6 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
}*/
|
||||
}
|
||||
|
||||
if (Lives() != PastLives()) {
|
||||
auto life = m_World->GetComponent<Components::Life>(entity);
|
||||
if (life != nullptr) {
|
||||
if (life->Number + 1 == PastLives()) {
|
||||
m_World->RemoveEntity(entity);
|
||||
SetPastLives(Lives());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ballComponent != nullptr) {
|
||||
if (!ballComponent->Sticky)
|
||||
{
|
||||
@@ -452,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<Components::Transform> transform = m_World->AddComponent<Components::Transform>(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<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
|
||||
lifeNr->Number = number;
|
||||
|
||||
auto model = m_World->AddComponent<Components::Model>(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);
|
||||
|
||||
@@ -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<ConfigFile>("Config.ini")->GetValue<bool>("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<Components::Template>(entity);
|
||||
if (templateCheck != nullptr){ return; }
|
||||
|
||||
if (Lives() != PastLives()) {
|
||||
auto life = m_World->GetComponent<Components::Life>(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<Components::Transform> transform = m_World->AddComponent<Components::Transform>(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<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
|
||||
lifeNr->Number = number;
|
||||
|
||||
auto model = m_World->AddComponent<Components::Model>(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;
|
||||
}
|
||||
Reference in New Issue
Block a user