From f6f74c659f491ee3474ef455230986fc41e78ad3 Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Thu, 8 Oct 2015 21:51:27 +0200 Subject: [PATCH] Getting Sticky after Ink Blaster now works. --- include/Game/BallSystem.h | 5 +++ include/Game/EInkBlasterOver.h | 25 +++++++++++++ include/Game/ProjectileSystem.h | 2 + src/game/Game/BallSystem.cpp | 59 +++++++++++++++++++++--------- src/game/Game/LevelSystem.cpp | 3 -- src/game/Game/ProjectileSystem.cpp | 11 ++++++ 6 files changed, 85 insertions(+), 20 deletions(-) create mode 100644 include/Game/EInkBlasterOver.h diff --git a/include/Game/BallSystem.h b/include/Game/BallSystem.h index d524bfe..6286507 100644 --- a/include/Game/BallSystem.h +++ b/include/Game/BallSystem.h @@ -23,6 +23,7 @@ #include "Game/EMultiBallLost.h" #include "Game/EStickyPad.h" #include "Game/EInkBlaster.h" +#include "Game/EInkBlasterOver.h" #include "Game/EGameOver.h" #include "Game/EPause.h" #include "Game/EHitPad.h" @@ -96,6 +97,8 @@ private: bool m_Waiting = true; bool m_Sticky = false; bool m_InkBlaster = false; + bool m_InkAttached = false; + bool m_BlockedWaiting = false; int m_StickyCounter = 5; glm::vec3 m_SavedSpeed; @@ -112,6 +115,7 @@ private: dd::EventRelay m_EMultiBall; dd::EventRelay m_EStickyPad; dd::EventRelay m_EInkBlaster; + dd::EventRelay m_EInkBlasterOver; dd::EventRelay m_EPause; dd::EventRelay m_Contact; dd::EventRelay m_EActionButton; @@ -123,6 +127,7 @@ private: bool OnMultiBall(const dd::Events::MultiBall &event); bool OnStickyPad(const dd::Events::StickyPad &event); bool OnInkBlaster(const dd::Events::InkBlaster &event); + bool OnInkBlasterOver(const dd::Events::InkBlasterOver &event); bool OnPause(const dd::Events::Pause &event); bool OnActionButton(const dd::Events::ActionButton &event); }; diff --git a/include/Game/EInkBlasterOver.h b/include/Game/EInkBlasterOver.h new file mode 100644 index 0000000..1d516b9 --- /dev/null +++ b/include/Game/EInkBlasterOver.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-10-08. +// + +#ifndef DAYDREAM_EINKBLASTEROVER_H +#define DAYDREAM_EINKBLASTEROVER_H + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Events +{ + +struct InkBlasterOver : Event +{ + EntityID Ball; +}; + +} + +} + +#endif //DAYDREAM_EINKBLASTEROVER_H diff --git a/include/Game/ProjectileSystem.h b/include/Game/ProjectileSystem.h index 7310044..14c3657 100644 --- a/include/Game/ProjectileSystem.h +++ b/include/Game/ProjectileSystem.h @@ -10,12 +10,14 @@ #include "Core/CTemplate.h" #include "Core/EventBroker.h" #include "Core/World.h" +#include "Core/EventBroker.h" #include "Physics/EContact.h" #include "Rendering/CModel.h" #include "Physics/CPhysics.h" #include "Physics/CCircleShape.h" #include "Game/EPause.h" #include "Game/EInkBlaster.h" +#include "Game/EInkBlasterOver.h" #include "Game/EActionButton.h" #include "Game/EHitPad.h" #include "Game/CProjectile.h" diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index c7a8b12..332b7db 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -20,6 +20,7 @@ void dd::Systems::BallSystem::Initialize() EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall); EVENT_SUBSCRIBE_MEMBER(m_EStickyPad, &BallSystem::OnStickyPad); EVENT_SUBSCRIBE_MEMBER(m_EInkBlaster, &BallSystem::OnInkBlaster); + EVENT_SUBSCRIBE_MEMBER(m_EInkBlasterOver, &BallSystem::OnInkBlasterOver); EVENT_SUBSCRIBE_MEMBER(m_EPause, &BallSystem::OnPause); EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &BallSystem::OnActionButton); @@ -109,19 +110,10 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID } if (ballComponent->Waiting) { - if (m_Waiting == false) { + if (!m_Waiting) { ballComponent->Waiting = false; - auto transform = m_World->GetComponent(entity); + auto transform = m_World->GetComponent(entity); 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); @@ -130,6 +122,18 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID return; } } + if (ballComponent->Sticky) { + if (!m_Waiting) + { + auto transform = m_World->GetComponent(entity); + transform->Velocity = ballComponent->SavedSpeed; + m_StickyCounter--; + if (m_StickyCounter > 0) { + m_Sticky = true; + } + ballComponent->Sticky = false; + } + } auto transformBall = m_World->GetComponent(entity); if (glm::abs(transformBall->Velocity.y) < 2) { @@ -273,15 +277,19 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event) ballComponent->Combo = 0; if (m_InkBlaster) { - m_InkBlaster = false; - ballComponent->Sticky = true; - ballComponent->StickyPlacement = glm::vec3(0, 0.5f, 0); - ballTransform->Velocity = glm::vec3(0.f, 0.f, 0.f); + if (!m_InkAttached) { + m_InkAttached = true; + m_Waiting = true; + m_BlockedWaiting = true; + ballComponent->Sticky = true; + ballComponent->StickyPlacement = glm::vec3(0, 0.5f, 0); + ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed; + ballTransform->Velocity = glm::vec3(0.f, 0.f, 0.f); + } } else if (m_Sticky) { m_Sticky = false; m_Waiting = true; ballComponent->Sticky = true; - ballComponent->Waiting = true; ballComponent->StickyPlacement = ballTransform->Position - padTransform->Position; ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed; ballTransform->Velocity *= -1; @@ -431,9 +439,26 @@ bool dd::Systems::BallSystem::OnInkBlaster(const dd::Events::InkBlaster &event) return true; } +bool dd::Systems::BallSystem::OnInkBlasterOver(const dd::Events::InkBlasterOver &event) +{ + auto ballComponent = m_World->GetComponent(event.Ball); + auto transform = m_World->GetComponent(event.Ball); + + m_InkBlaster = false; + m_InkAttached = false; + m_BlockedWaiting = false; + m_Sticky = true; + ballComponent->SavedSpeed = glm::normalize(glm::vec3(0.f, 1.f, 0.f)) * ballComponent->Speed; + m_Waiting = false; + transform->Velocity = glm::normalize(glm::vec3(0.f, 1, 0.f)) * ballComponent->Speed; + return true; +} + bool dd::Systems::BallSystem::OnActionButton(const dd::Events::ActionButton &event) { - m_Waiting = false; + if (!m_BlockedWaiting) { + m_Waiting = false; + } return true; } diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index c24bc8d..8111fdd 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -225,7 +225,6 @@ void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity) bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event) { - LOG_DEBUG("Collision happened!"); EntityID entityBrick; EntityID entityBall; EntityID entityShot = 0; @@ -250,12 +249,10 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event) } else { auto shot = m_World->GetComponent(event.Entity1); if (shot != nullptr) { - LOG_DEBUG("Entity1 is a shot!"); entityShot = event.Entity1; } else { shot = m_World->GetComponent(event.Entity2); if (shot != nullptr) { - LOG_DEBUG("Entity2 is a shot!"); entityShot = event.Entity2; } else { return false; diff --git a/src/game/Game/ProjectileSystem.cpp b/src/game/Game/ProjectileSystem.cpp index 3bf977b..224d86b 100644 --- a/src/game/Game/ProjectileSystem.cpp +++ b/src/game/Game/ProjectileSystem.cpp @@ -118,6 +118,17 @@ bool dd::Systems::ProjectileSystem::OnActionButton(const dd::Events::ActionButto m_SquidLoaded = false; ball->InkBlaster = false; ball->Sticky = false; + ball->Waiting = true; + + { + Events::InkBlasterOver e; + e.Ball = m_AttachedSquid; + EventBroker->Publish(e); + } + { + Events::ActionButton e; + EventBroker->Publish(e); + } } } return true;