diff --git a/include/Core/Engine.h b/include/Core/Engine.h index 9cddd22..999f843 100755 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -187,6 +187,7 @@ public: auto transform = m_World->AddComponent(t_halfPipe); transform->Position = glm::vec3(0.f, 34.6f, -15.f); transform->Scale = glm::vec3(6.f, 6.f, 10.f); + transform->Sticky = false; auto model = m_World->AddComponent(t_halfPipe); model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj"; model->Color = glm::vec4(0.8f, 0.8f, 0.8f, 0.3f); diff --git a/include/Game/BallSystem.h b/include/Game/BallSystem.h index ab2b79e..b7ded69 100644 --- a/include/Game/BallSystem.h +++ b/include/Game/BallSystem.h @@ -21,6 +21,7 @@ #include "Game/EResetBall.h" #include "Game/EMultiBall.h" #include "Game/EMultiBallLost.h" +#include "Game/EStickyPad.h" #include "Game/EGameOver.h" #include "Game/EPause.h" #include "Game/EHitPad.h" @@ -92,6 +93,8 @@ private: bool m_ReplaceBall = false; bool m_Pause = false; bool m_Waiting = true; + bool m_Sticky = false; + int m_StickyCounter = 5; EntityID m_LastCollision = 999999; glm::vec3 m_SavedSpeed; @@ -106,6 +109,7 @@ private: dd::EventRelay m_EMultiBallLost; dd::EventRelay m_EResetBall; dd::EventRelay m_EMultiBall; + dd::EventRelay m_EStickyPad; dd::EventRelay m_EPause; dd::EventRelay m_Contact; dd::EventRelay m_EActionButton; @@ -115,6 +119,7 @@ private: 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 OnPause(const dd::Events::Pause &event); bool OnActionButton(const dd::Events::ActionButton &event); }; diff --git a/include/Game/CBall.h b/include/Game/CBall.h index 0330ed9..bd9698a 100644 --- a/include/Game/CBall.h +++ b/include/Game/CBall.h @@ -20,6 +20,8 @@ struct Ball : Component int Combo = 0; bool Paused = false; bool Waiting = true; + bool Sticky = false; + glm::vec3 StickyPlacement = glm::vec3(0, 0, 0); glm::vec3 SavedSpeed = glm::vec3(0, 0, 0); }; diff --git a/include/Game/EStickyPad.h b/include/Game/EStickyPad.h new file mode 100644 index 0000000..bdaa47e --- /dev/null +++ b/include/Game/EStickyPad.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-10-08. +// + +#ifndef DAYDREAM_ESTICKYPAD_H +#define DAYDREAM_ESTICKYPAD_H + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Events +{ + +struct StickyPad : Event +{ + Components::Transform* Transform; +}; + +} + +} + +#endif //DAYDREAM_ESTICKYPAD_H diff --git a/include/Game/LevelSystem.h b/include/Game/LevelSystem.h index 6fc6443..2f7d637 100755 --- a/include/Game/LevelSystem.h +++ b/include/Game/LevelSystem.h @@ -23,6 +23,7 @@ #include "Game/EComboEvent.h" #include "Game/EHitPad.h" #include "Game/ELifebuoy.h" +#include "Game/EStickyPad.h" #include "Game/EMultiBall.h" #include "Game/EMultiBallLost.h" #include "Game/EPause.h" @@ -109,7 +110,7 @@ private: bool m_Initialized = false; bool m_Pause = false; int m_LooseBricks = 0; - int m_CurrentCluster = 2; + int m_CurrentCluster = 1; int m_CurrentLevel = 1; int m_MultiBalls = 0; int m_PowerUps = 0; @@ -125,6 +126,7 @@ private: const int StandardBrick = 1; const int MultiBallBrick = 2; const int LifebuoyBrick = 3; + const int StickyBrick = 4; EntityID m_BrickTemplate; diff --git a/include/Game/LifebuoySystem.h b/include/Game/LifebuoySystem.h index d30be4d..1a7ae6e 100644 --- a/include/Game/LifebuoySystem.h +++ b/include/Game/LifebuoySystem.h @@ -56,11 +56,11 @@ private: struct LifeBuoyInfo { EntityID Entity; - float TimeToLive = 20.f; + float TimeToLive = 15.f; }; - float m_LeftEdge = -4.f; - float m_RightEdge = 4.f; + float m_LeftEdge = -3.8f; + float m_RightEdge = 3.8f; std::list m_LifeBuoys; }; diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index 8f636e5..37cc36c 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -18,6 +18,7 @@ void dd::Systems::BallSystem::Initialize() 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_EPause, &BallSystem::OnPause); EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &BallSystem::OnActionButton); @@ -103,12 +104,27 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID if (templateCheck != nullptr){ return; } if (ballComponent != nullptr) { + if (ReplaceBall()) { + SetReplaceBall(false); + m_Waiting = true; + ballComponent->Waiting = true; + } + if (ballComponent->Waiting) { if (m_Waiting == false) { ballComponent->Waiting = false; auto transform = m_World->GetComponent(entity); - transform->Velocity = glm::normalize(glm::vec3(0.5f, 1, 0.f)) * ballComponent->Speed; - } else { + transform->Velocity = glm::normalize(glm::vec3(-0.5f, 1, 0.f)) * ballComponent->Speed; + if (ballComponent->Sticky) { + transform->Velocity = ballComponent->SavedSpeed; + m_StickyCounter--; + std::cout << m_StickyCounter << std::endl; + if (m_StickyCounter > 0) { + m_Sticky = true; + } + ballComponent->Sticky = false; + } + } 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); @@ -116,12 +132,7 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID return; } } - if (ReplaceBall()) { - SetReplaceBall(false); - m_Waiting = true; - ballComponent->Waiting = true; - } - + auto transformBall = m_World->GetComponent(entity); if (glm::abs(transformBall->Velocity.y) < 2) { if (transformBall->Velocity.y > 0) { @@ -130,7 +141,7 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID transformBall->Velocity.y = -2; } } - if (transformBall->Position.y < -EdgeY() - 4) { + if (transformBall->Position.y < -EdgeY() - 4 || transformBall->Position.y > EdgeY() + 4) { if (MultiBalls() != 0) { m_World->RemoveEntity(entity); Events::MultiBallLost e; @@ -245,7 +256,9 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event) glm::vec2 ballVelocity = glm::vec2(ballTransform->Velocity.x, ballTransform->Velocity.y); - if (m_World->GetProperty(otherEntitiy, "Name") == "Pad"){ + if (m_World->GetProperty(otherEntitiy, "Name") == "Pad") { + auto padTransform = m_World->GetComponent(otherEntitiy); + Events::HitPad e; EventBroker->Publish(e); // Events::HitLag el; @@ -253,13 +266,24 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event) //el.Type = "All"; // EventBroker->Publish(el); - auto padTransform = m_World->GetComponent(otherEntitiy); - float x = (ballTransform->Position.x - padTransform->Position.x) * XMovementMultiplier(); - + + float x = (ballTransform->Position.x - padTransform->Position.x) * XMovementMultiplier(); float y = glm::cos((abs(x) / (1.6f)) * glm::pi() / 2.f) + 1.f; + ballComponent->Combo = 0; + + if (m_Sticky) { + m_Sticky = false; + m_Waiting = true; + ballComponent->Sticky = true; + ballComponent->Waiting = true; + ballComponent->StickyPlacement = padTransform->Position - ballTransform->Position; + ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed; + ballTransform->Velocity *= -1; + return true; + } + ballTransform->Velocity = glm::normalize(glm::vec3(x, y ,0.f)) * ballComponent->Speed; - ballComponent->Combo = 0; Events::ComboEvent ec; ec.Combo = ballComponent->Combo; ec.Ball = ballEntity; @@ -297,20 +321,13 @@ void dd::Systems::BallSystem::ResolveContacts() { for (auto c : m_Contacts) { - int count = 0; EntityID entity = c.first; std::list contactNormals = c.second; glm::vec2 finalNormal = glm::vec2(0.f); for (auto it = contactNormals.begin(); it != contactNormals.end(); it++) { finalNormal = finalNormal + (*it); - count++; } finalNormal = glm::normalize(finalNormal); - - if (count > 1) { - LOG_INFO("MultiCollision %i", count); - } - auto transform = m_World->GetComponent(entity); glm::vec2 velocity = glm::vec2(transform->Velocity.x, transform->Velocity.y); glm::vec2 reflectedVelocity = glm::reflect(velocity, finalNormal); @@ -403,6 +420,13 @@ bool dd::Systems::BallSystem::OnMultiBall(const dd::Events::MultiBall &event) return true; } +bool dd::Systems::BallSystem::OnStickyPad(const dd::Events::StickyPad &event) +{ + m_Sticky = true; + m_StickyCounter = 5; + return true; +} + bool dd::Systems::BallSystem::OnActionButton(const dd::Events::ActionButton &event) { m_Waiting = false; diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index 2c94dd3..bc6fcee 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -65,7 +65,7 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID // Check the background. auto model = m_World->GetComponent(entity); if (model != nullptr) { - if (model->ModelFile == "Models/Test/halfpipe/Halfpipe.obj") { + if (model->ModelFile == "Models/Test/halfpipe/Halfpipe.obj") { auto transform = m_World->GetComponent(entity); if (transform->Position.y <= -34.6) { transform->Position.y = 34.6; @@ -87,6 +87,9 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID Events::Lifebuoy e; e.Transform = transform; EventBroker->Publish(e); + } else if (brick->Type == StickyBrick) { + Events::StickyPad e; + EventBroker->Publish(e); } m_LooseBricks--; m_World->RemoveEntity(entity); @@ -194,6 +197,12 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe model->ModelFile = "Models/Brick/IceBrick.obj"; } else if (typeInt == LifebuoyBrick) { cBrick->Type = LifebuoyBrick; + auto model = m_World->GetComponent(brick); + model->Color = glm::vec4(1.f, 0.f, 0.f, .0f); + } else if (typeInt == StickyBrick) { + cBrick->Type = StickyBrick; + auto model = m_World->GetComponent(brick); + model->Color = glm::vec4(0.f, 0.f, 1.f, .0f); } float x = line * spacesBetweenBricks.x; float y = row * spacesBetweenBricks.y; @@ -370,7 +379,9 @@ void dd::Systems::LevelSystem::GetNextLevel() // 0 is empty space. // 1 is standard brick. // 2 is multiball brick. - if (m_CurrentCluster == 1) { + // 3 is lifebuoy brick. + // 4 is sticky brick. + if (m_CurrentCluster == 0) { if (m_CurrentLevel == 1) { level = {0, 0, 0, 0, 0, 0, 0, @@ -412,7 +423,7 @@ void dd::Systems::LevelSystem::GetNextLevel() 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; } - } else if (m_CurrentCluster == 2) { + } else if (m_CurrentCluster == 1) { if (m_CurrentLevel == 1) { level = {1, 1, 0, 1, 0, 1, 1, @@ -420,7 +431,7 @@ void dd::Systems::LevelSystem::GetNextLevel() 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 1, 1, 0, 1, 0, 1, 1, - 1, 3, 3, 3, 3, 3, 1}; + 4, 0, 0, 3, 0, 0, 1}; } else if (m_CurrentLevel == 2) { level = {1, 0, 0, 0, 0, 0, 1, diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp index f724376..b809ff4 100755 --- a/src/game/Game/PadSystem.cpp +++ b/src/game/Game/PadSystem.cpp @@ -57,6 +57,16 @@ void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID p { auto templateCheck = m_World->GetComponent(entity); if (templateCheck != nullptr){ return; } + + auto ball = m_World->GetComponent(entity); + if (ball != nullptr) { + if (ball->Sticky) { + auto transform = m_World->GetComponent(entity); + transform->Position = Transform()->Position; + transform->Position -= ball->StickyPlacement; + transform->Orientation = glm::quat(); + } + } } void dd::Systems::PadSystem::Update(double dt) @@ -155,7 +165,10 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) { e.Time = 0.2; e.Type = "All"; EventBroker->Publish(e); - } else if (val == GLFW_KEY_SPACE) { + } else if (val == GLFW_KEY_S) { + Events::StageCleared e; + EventBroker->Publish(e); + } else if (val == GLFW_KEY_SPACE) { Events::ActionButton e; EventBroker->Publish(e); } else if (val == GLFW_KEY_D) { diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp index cbe084a..3548875 100755 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -22,8 +22,8 @@ void dd::Systems::PhysicsSystem::Initialize() InitializeWater(); EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse); EVENT_SUBSCRIBE_MEMBER(m_EPause, &PhysicsSystem::OnPause); + EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PhysicsSystem::OnStageCleared); EVENT_SUBSCRIBE_MEMBER(m_ECreateParticleSequence, &PhysicsSystem::CreateParticleSequence); - } void dd::Systems::PhysicsSystem::InitializeWater() @@ -253,12 +253,13 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity if (m_Travelling) { auto transform = m_World->GetComponent(entity); if (transform != nullptr) { - if (transform->Sticky == true) { - return; + if (!transform->Sticky) { + transform->Position.y -= 6.0f * dt; } + } else { transform->Position.y -= 6.0f * dt; - } - } + } + } auto particle = m_World->GetComponent(entity); auto pTemplate = m_World->GetComponent(entity); if (particle && !pTemplate) {