From 6669d91a90b5a43c097d5dbd67a0f72f8e87da23 Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Thu, 8 Oct 2015 15:42:13 +0200 Subject: [PATCH 1/4] Sticky works except graphics. Temporarily colored odd bricks. --- include/Game/BallSystem.h | 5 ++++ include/Game/CBall.h | 2 ++ include/Game/EStickyPad.h | 25 ++++++++++++++++++++ include/Game/LevelSystem.h | 4 +++- src/game/Core/Renderer.cpp | 2 +- src/game/Game/BallSystem.cpp | 44 +++++++++++++++++++++++++++++------ src/game/Game/LevelSystem.cpp | 17 +++++++++++--- src/game/Game/PadSystem.cpp | 10 ++++++++ 8 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 include/Game/EStickyPad.h diff --git a/include/Game/BallSystem.h b/include/Game/BallSystem.h index 01f5cc5..8399209 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" @@ -91,6 +92,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; @@ -105,6 +108,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; @@ -114,6 +118,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/src/game/Core/Renderer.cpp b/src/game/Core/Renderer.cpp index f43876f..6abf221 100755 --- a/src/game/Core/Renderer.cpp +++ b/src/game/Core/Renderer.cpp @@ -59,7 +59,7 @@ void dd::Renderer::Initialize() } // Create default camera - m_DefaultCamera = std::unique_ptr(new dd::Camera((float)m_Resolution.Width / m_Resolution.Height, /*45.f*/ 46.f, 0.01f, 5000.f)); + m_DefaultCamera = std::unique_ptr(new dd::Camera((float)m_Resolution.Width / m_Resolution.Height, 45.f, 0.01f, 5000.f)); m_DefaultCamera->SetPosition(glm::vec3(0, 0, 0)); if (m_Camera == nullptr) { m_Camera = m_DefaultCamera.get(); diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index 2f68824..9802c08 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); @@ -107,8 +108,17 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID 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); @@ -245,7 +255,9 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event) auto ballTransform = m_World->GetComponent(ballEntity); 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 +265,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; @@ -400,6 +423,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 06552d3..4b546f7 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -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, 0, 0, 3, 0, 0, 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 e88ceee..6e4d454 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) From 74d7e1feb74a00cebff31ab7844ab8ca7913e5a5 Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Thu, 8 Oct 2015 16:13:30 +0200 Subject: [PATCH 2/4] Slight calibration so Travelling doesn't necessarily kill the process just because something is Sticky. --- src/game/Physics/PhysicsSystem.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp index 075f287..86b7d9f 100755 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -254,10 +254,9 @@ 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; } - transform->Position.y -= 6.0f * dt; } } auto particle = m_World->GetComponent(entity); From 3ac6fdce5ffc8a060d9b1f40d088932f6bd4438d Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Thu, 8 Oct 2015 16:53:51 +0200 Subject: [PATCH 3/4] Fixes smaller problems --- include/Core/Engine.h | 1 + src/game/Game/BallSystem.cpp | 13 +++++++------ src/game/Game/LevelSystem.cpp | 2 +- src/game/Game/PadSystem.cpp | 5 ++++- src/game/Physics/PhysicsSystem.cpp | 2 ++ 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/Core/Engine.h b/include/Core/Engine.h index cc771b9..09db604 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/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index 9802c08..ae57913 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -104,6 +104,12 @@ 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; @@ -126,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) { diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index b187a98..a96038a 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; diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp index 6e4d454..55d8790 100755 --- a/src/game/Game/PadSystem.cpp +++ b/src/game/Game/PadSystem.cpp @@ -165,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 86b7d9f..001a048 100755 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -257,6 +257,8 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity if (!transform->Sticky) { transform->Position.y -= 6.0f * dt; } + } else { + transform->Position.y -= 6.0f * dt; } } auto particle = m_World->GetComponent(entity); From c76033113dd42ade97a8c0d0e24a1ae3058e8e8d Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Thu, 8 Oct 2015 17:15:48 +0200 Subject: [PATCH 4/4] Small edit to temporarily solve a problem. --- src/game/Game/BallSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index ae57913..ce36cb8 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -141,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;