diff --git a/include/Core/Engine.h b/include/Core/Engine.h index c07919b..bf10872 100644 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -183,10 +183,12 @@ public: //Water test { + float amount = 1.5f; + auto t_waterBody = m_World->CreateEntity(); auto transform = m_World->AddComponent(t_waterBody); - transform->Position = glm::vec3(0.f, -5.5f, -10.f); - transform->Scale = glm::vec3(7.f, 1.5f, 1.f); + transform->Position = glm::vec3(0.f, -6.25f + (amount / 2), -10.f); + transform->Scale = glm::vec3(7.f, amount, 1.f); auto water = m_World->AddComponent(t_waterBody); auto body = m_World->AddComponent(t_waterBody); m_World->CommitEntity(t_waterBody); @@ -235,7 +237,7 @@ public: // m_World->CommitEntity(topWall); // } - { + /*{ auto topWall = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent( topWall); @@ -254,14 +256,14 @@ public: physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick; m_World->CommitEntity(topWall); - } + }*/ { auto leftWall = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent( leftWall); transform->Position = glm::vec3(-4.f, 1.f, -10.f); - transform->Scale = glm::vec3(0.5f, 20.f, 1.f); + transform->Scale = glm::vec3(0.5f, 35.f, 1.f); std::shared_ptr sprite = m_World->AddComponent(leftWall); sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; @@ -282,7 +284,7 @@ public: std::shared_ptr transform = m_World->AddComponent( rightWall); transform->Position = glm::vec3(4.f, 1.f, -10.f); - transform->Scale = glm::vec3(0.5f, 20.f, 1.f); + transform->Scale = glm::vec3(0.5f, 35.f, 1.f); std::shared_ptr sprite = m_World->AddComponent(rightWall); sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; diff --git a/include/Game/BallSystem.h b/include/Game/BallSystem.h index f56a08a..95dfad6 100644 --- a/include/Game/BallSystem.h +++ b/include/Game/BallSystem.h @@ -90,6 +90,9 @@ private: bool m_MultiBall = false; bool m_Pause = false; + glm::vec3 m_SavedSpeed; + bool m_InitializePause = false; + EntityID m_Ball; dd::EventRelay m_ELifeLost; diff --git a/include/Game/CBall.h b/include/Game/CBall.h index 5dd1405..fbf720a 100644 --- a/include/Game/CBall.h +++ b/include/Game/CBall.h @@ -18,6 +18,8 @@ struct Ball : Component int Number = 0; float Speed = 5.f; int Combo = 0; + bool Paused = false; + glm::vec3 SavedSpeed = glm::vec3(0, 0, 0); }; } diff --git a/include/Game/EPause.h b/include/Game/EPause.h index b6d2505..ab27306 100644 --- a/include/Game/EPause.h +++ b/include/Game/EPause.h @@ -15,7 +15,7 @@ namespace Events struct Pause : Event { - + std::string Type; }; } diff --git a/include/Game/HitLagSystem.h b/include/Game/HitLagSystem.h index 8367dd6..2d9fa3f 100644 --- a/include/Game/HitLagSystem.h +++ b/include/Game/HitLagSystem.h @@ -57,16 +57,24 @@ public: void Initialize() override; void Update(double dt) override; + void FlipPause(); bool IsPaused() const { return m_Pause; } void SetPause(const bool& pause) { m_Pause = pause; } bool HitLag() const { return m_HitLag; } void SetHitLag(const bool& hitLag) { m_HitLag = hitLag; } + float& HitLagDuration() { return m_HitLagDuration; } + void SetHitLagDuration(const float& hitLagDuration) { m_HitLagDuration = hitLagDuration; } + float& HitLagTimer() { return m_HitLagTimer; } + void SetHitLagTimer(const float& hitLagTimer) { m_HitLagTimer = hitLagTimer; } + std::string& CurrentType() { return m_CurrentType; } + void SetCurrentType(const std::string& currentType) { m_CurrentType = currentType; } private: bool m_Pause; bool m_HitLag; float m_HitLagDuration; float m_HitLagTimer; + std::string m_CurrentType; dd::EventRelay m_EPause; dd::EventRelay m_EHitLag; diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index 84e103e..36435ba 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -71,15 +71,34 @@ void dd::Systems::BallSystem::Update(double dt) void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { + auto ballComponent = m_World->GetComponent(entity); if (IsPaused()) { + if (ballComponent != nullptr) { + auto transform = m_World->GetComponent(entity); + + if (!ballComponent->Paused) { + ballComponent->Paused = true; + ballComponent->SavedSpeed = transform->Velocity; + transform->Velocity = glm::vec3(0, 0, 0); + } + } return; + } else { + if (ballComponent != nullptr) { + auto transform = m_World->GetComponent(entity); + + if (ballComponent->Paused) { + transform->Velocity = ballComponent->SavedSpeed; + ballComponent->Paused = false; + } + } } auto templateCheck = m_World->GetComponent(entity); if (templateCheck != nullptr){ return; } - auto ballComponent = m_World->GetComponent(entity); + if (ballComponent != nullptr) { - if (ReplaceBall() == true) { + if (ReplaceBall()) { SetReplaceBall(false); auto transform = m_World->GetComponent(entity); @@ -153,6 +172,10 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID bool dd::Systems::BallSystem::OnPause(const dd::Events::Pause &event) { + if (event.Type != "BallSystem" && event.Type != "All") { + return false; + } + if (IsPaused()) { SetPause(false); } else { diff --git a/src/game/Game/HitLagSystem.cpp b/src/game/Game/HitLagSystem.cpp index 92deb9a..da2b25f 100644 --- a/src/game/Game/HitLagSystem.cpp +++ b/src/game/Game/HitLagSystem.cpp @@ -15,19 +15,25 @@ void dd::Systems::HitLagSystem::Update(double dt) { if (IsPaused()) { if (HitLag()) { - m_HitLagTimer += dt; - std::cout << m_HitLagTimer << std::endl; - if (m_HitLagDuration < m_HitLagTimer) { - m_HitLagTimer = 0; + SetHitLagTimer(HitLagTimer() += dt); + std::cout << HitLagTimer() << std::endl; + if (HitLagDuration() < HitLagTimer()) { + SetHitLagTimer(0); SetHitLag(false); - Events::Pause e; - EventBroker->Publish(e); + FlipPause(); } } return; } } +void dd::Systems::HitLagSystem::FlipPause() +{ + Events::Pause e; + e.Type = CurrentType(); + EventBroker->Publish(e); +} + bool dd::Systems::HitLagSystem::OnPause(const dd::Events::Pause &event) { if (IsPaused()) { @@ -40,9 +46,12 @@ bool dd::Systems::HitLagSystem::OnPause(const dd::Events::Pause &event) bool dd::Systems::HitLagSystem::OnHitLag(const dd::Events::HitLag &event) { + if (HitLag()) { + FlipPause(); + } SetHitLag(true); - Events::Pause e; - EventBroker->Publish(e); - m_HitLagDuration = event.Time; + SetCurrentType(event.Type); + FlipPause(); + SetHitLagDuration(event.Time); return true; } \ No newline at end of file diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index c85132a..c411701 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -77,6 +77,10 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID bool dd::Systems::LevelSystem::OnPause(const dd::Events::Pause &event) { + if (event.Type != "LevelSystem" && event.Type != "All") { + return false; + } + if (IsPaused()) { SetPause(false); } else { diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp index becb0f6..1eb5744 100755 --- a/src/game/Game/PadSystem.cpp +++ b/src/game/Game/PadSystem.cpp @@ -111,6 +111,10 @@ void dd::Systems::PadSystem::Update(double dt) bool dd::Systems::PadSystem::OnPause(const dd::Events::Pause &event) { + if (event.Type != "PadSystem" && event.Type != "All") { + return false; + } + if (IsPaused()) { SetPause(false); } else { @@ -143,10 +147,11 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) EventBroker->Publish(e); } else if (val == GLFW_KEY_P) { Events::Pause e; + e.Type = "All"; EventBroker->Publish(e); } else if (val == GLFW_KEY_H) { Events::HitLag e; - e.Time = 0.3; + e.Time = 0.2; e.Type = "All"; EventBroker->Publish(e); } else if (val == GLFW_KEY_D) { diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp index b0bd283..effdfa4 100644 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -179,6 +179,10 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event) { + if (event.Type != "PhysicsSystem" && event.Type != "All") { + return false; + } + if (IsPaused()) { SetPause(false); } else {