From 5630771272645e6690f87de13cc76b9f6e69f707 Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Mon, 12 Oct 2015 16:45:59 +0200 Subject: [PATCH] Fixed Sticky after Ink bug, fixed directions on Squid after sticky, laser direction is in background. Brick Components implemented, though they do nothing. --- include/Core/Engine.h | 14 ++++++++- include/Game/BallSystem.h | 1 + include/Game/BrickComponents.h | 15 ++++++++++ include/Game/CBrick.h | 9 ++++++ include/Game/CInkBlasterBrick.h | 25 ++++++++++++++++ include/Game/CKrakenAttackBrick.h | 25 ++++++++++++++++ include/Game/CLifebuoyBrick.h | 25 ++++++++++++++++ include/Game/CMultiBallBrick.h | 25 ++++++++++++++++ include/Game/CStandardBrick.h | 25 ++++++++++++++++ include/Game/CStickyAim.h | 25 ++++++++++++++++ include/Game/CStickyBrick.h | 25 ++++++++++++++++ include/Game/LevelSystem.h | 6 +++- include/Game/PadSystem.h | 8 +++++ src/game/Game/BallSystem.cpp | 14 +++++---- src/game/Game/LevelSystem.cpp | 7 +++++ src/game/Game/PadSystem.cpp | 49 ++++++++++++++++++++++++++++--- 16 files changed, 286 insertions(+), 12 deletions(-) create mode 100644 include/Game/BrickComponents.h create mode 100644 include/Game/CInkBlasterBrick.h create mode 100644 include/Game/CKrakenAttackBrick.h create mode 100644 include/Game/CLifebuoyBrick.h create mode 100644 include/Game/CMultiBallBrick.h create mode 100644 include/Game/CStandardBrick.h create mode 100644 include/Game/CStickyAim.h create mode 100644 include/Game/CStickyBrick.h diff --git a/include/Core/Engine.h b/include/Core/Engine.h index 742c375..777c943 100755 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -31,14 +31,15 @@ //TODO: Remove includes that are only here for the temporary draw solution. #include "World.h" #include "CTransform.h" +#include "CTemplate.h" #include "Core/EventBroker.h" #include "Rendering/CModel.h" #include "Rendering/CSprite.h" -#include "CTemplate.h" #include "Rendering/CPointLight.h" #include "Transform/TransformSystem.h" #include "Sound/SoundSystem.h" #include "Sound/CCollisionSound.h" + #include "Game/LevelSystem.h" #include "Game/PadSystem.h" #include "Game/CBall.h" @@ -46,12 +47,15 @@ #include "Game/CLifebuoy.h" #include "Game/CProjectile.h" #include "Game/CBrick.h" +#include "Game/CStickyAim.h" #include "Game/BallSystem.h" #include "Game/HitLagSystem.h" #include "Game/LifebuoySystem.h" #include "Game/ProjectileSystem.h" #include "Game/Bricks/CPowerUpBrick.h" +#include "Game/BrickComponents.h" + #include "Physics/PhysicsSystem.h" #include "Physics/CPhysics.h" #include "Physics/CRectangleShape.h" @@ -116,10 +120,18 @@ public: m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); + m_World->SystemFactory.Register( [this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); }); m_World->AddSystem(); diff --git a/include/Game/BallSystem.h b/include/Game/BallSystem.h index 5ae65c2..76202f5 100644 --- a/include/Game/BallSystem.h +++ b/include/Game/BallSystem.h @@ -11,6 +11,7 @@ #include "Physics/CRectangleShape.h" #include "Physics/EContact.h" #include "Rendering/CModel.h" +#include "Rendering/CSprite.h" #include "Rendering/CPointLight.h" #include "Game/CBall.h" #include "Game/CPowerUp.h" diff --git a/include/Game/BrickComponents.h b/include/Game/BrickComponents.h new file mode 100644 index 0000000..92c568a --- /dev/null +++ b/include/Game/BrickComponents.h @@ -0,0 +1,15 @@ +// +// Created by Adniklastrator on 2015-10-12. +// + +#ifndef DAYDREAM_CBRICKCOMPONENTS_H +#define DAYDREAM_CBRICKCOMPONENTS_H + +#include "Game/CStandardBrick.h" +#include "Game/CMultiBallBrick.h" +#include "Game/CLifebuoyBrick.h" +#include "Game/CStickyBrick.h" +#include "Game/CInkBlasterBrick.h" +#include "Game/CKrakenAttackBrick.h" + +#endif //DAYDREAM_CBRICKCOMPONENTS_H diff --git a/include/Game/CBrick.h b/include/Game/CBrick.h index f55734a..7b477cf 100644 --- a/include/Game/CBrick.h +++ b/include/Game/CBrick.h @@ -18,6 +18,15 @@ struct Brick : Component int Score = 50; int Type = 0; bool Removed = false; + + //What number of types each is. + const int EmptyBrickSpace = 0; + const int StandardBrick = 1; + const int MultiBallBrick = 2; + const int LifebuoyBrick = 3; + const int StickyBrick = 4; + const int InkBlasterBrick = 5; + const int KrakenAttackBrick = 6; }; } diff --git a/include/Game/CInkBlasterBrick.h b/include/Game/CInkBlasterBrick.h new file mode 100644 index 0000000..786c44f --- /dev/null +++ b/include/Game/CInkBlasterBrick.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-10-12. +// + +#ifndef DAYDREAM_CINKBLASTERBRICK_H +#define DAYDREAM_CINKBLASTERBRICK_H + +#include "Core/Component.h" + +namespace dd +{ + +namespace Components +{ + +struct InkBlasterBrick : Component +{ + +}; + +} + +} + +#endif //DAYDREAM_CINKBLASTERBRICK_H diff --git a/include/Game/CKrakenAttackBrick.h b/include/Game/CKrakenAttackBrick.h new file mode 100644 index 0000000..d4e1048 --- /dev/null +++ b/include/Game/CKrakenAttackBrick.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-10-12. +// + +#ifndef DAYDREAM_CKRAKENATTACKBRICK_H +#define DAYDREAM_CKRAKENATTACKBRICK_H + +#include "Core/Component.h" + +namespace dd +{ + +namespace Components +{ + +struct KrakenAttackBrick : Component +{ + +}; + +} + +} + +#endif //DAYDREAM_CKRAKENATTACKBRICK_H diff --git a/include/Game/CLifebuoyBrick.h b/include/Game/CLifebuoyBrick.h new file mode 100644 index 0000000..84426ae --- /dev/null +++ b/include/Game/CLifebuoyBrick.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-10-12. +// + +#ifndef DAYDREAM_CLIFEBUOYBRICK_H +#define DAYDREAM_CLIFEBUOYBRICK_H + +#include "Core/Component.h" + +namespace dd +{ + +namespace Components +{ + +struct LifebuoyBrick : Component +{ + +}; + +} + +} + +#endif //DAYDREAM_CLIFEBUOYBRICK_H diff --git a/include/Game/CMultiBallBrick.h b/include/Game/CMultiBallBrick.h new file mode 100644 index 0000000..15bf95a --- /dev/null +++ b/include/Game/CMultiBallBrick.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-10-12. +// + +#ifndef DAYDREAM_CMULTIBALLBRICK_H +#define DAYDREAM_CMULTIBALLBRICK_H + +#include "Core/Component.h" + +namespace dd +{ + +namespace Components +{ + +struct MultiBallBrick : Component +{ + +}; + +} + +} + +#endif //DAYDREAM_CMULTIBALLBRICK_H diff --git a/include/Game/CStandardBrick.h b/include/Game/CStandardBrick.h new file mode 100644 index 0000000..667f6ed --- /dev/null +++ b/include/Game/CStandardBrick.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-10-12. +// + +#ifndef DAYDREAM_CSTANDARDBRICK_H +#define DAYDREAM_CSTANDARDBRICK_H + +#include "Core/Component.h" + +namespace dd +{ + +namespace Components +{ + +struct StandardBrick : Component +{ + +}; + +} + +} + +#endif //DAYDREAM_CSTANDARDBRICK_H diff --git a/include/Game/CStickyAim.h b/include/Game/CStickyAim.h new file mode 100644 index 0000000..7804761 --- /dev/null +++ b/include/Game/CStickyAim.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-10-12. +// + +#ifndef DAYDREAM_CSTICKYAIM_H +#define DAYDREAM_CSTICKYAIM_H + +#include "Core/Component.h" + +namespace dd +{ + +namespace Components +{ + +struct StickyAim : Component +{ + bool Aiming = false; +}; + +} + +} + +#endif //DAYDREAM_CSTICKYAIM_H diff --git a/include/Game/CStickyBrick.h b/include/Game/CStickyBrick.h new file mode 100644 index 0000000..742e97a --- /dev/null +++ b/include/Game/CStickyBrick.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-10-12. +// + +#ifndef DAYDREAM_CSTICKYBRICK_H +#define DAYDREAM_CSTICKYBRICK_H + +#include "Core/Component.h" + +namespace dd +{ + +namespace Components +{ + +struct StickyBrick : Component +{ + +}; + +} + +} + +#endif //DAYDREAM_CSTICKYBRICK_H diff --git a/include/Game/LevelSystem.h b/include/Game/LevelSystem.h index c9f3081..020baac 100755 --- a/include/Game/LevelSystem.h +++ b/include/Game/LevelSystem.h @@ -12,11 +12,15 @@ #include "Core/World.h" #include "Rendering/CSprite.h" #include "Rendering/CModel.h" + #include "Game/CBrick.h" #include "Game/CBall.h" #include "Game/CLife.h" #include "Game/CProjectile.h" #include "Game/CPowerUp.h" + +#include "Game/BrickComponents.h" + #include "Game/EStageCleared.h" #include "Game/ELifeLost.h" #include "Game/EResetBall.h" @@ -34,7 +38,7 @@ #include "Game/EClusterClear.h" #include "Game/ECreatePowerUp.h" #include "Game/EPowerUpTaken.h" -//#include "Game/Bricks/CPowerUpBrick.h" + #include "Physics/CPhysics.h" #include "Physics/CCircleShape.h" #include "Physics/CRectangleShape.h" diff --git a/include/Game/PadSystem.h b/include/Game/PadSystem.h index 6d02e44..0377b2b 100755 --- a/include/Game/PadSystem.h +++ b/include/Game/PadSystem.h @@ -24,8 +24,11 @@ #include "Game/CBall.h" #include "Game/CPad.h" #include "Game/CPowerUp.h" +#include "Game/CStickyAim.h" #include "Game/EResetBall.h" #include "Game/EMultiBall.h" +#include "Game/EStickyPad.h" +#include "Game/EInkBlaster.h" #include "Game/EKrakenAttack.h" #include "Game/EPowerUpTaken.h" #include "Game/EStageCleared.h" @@ -78,12 +81,15 @@ private: bool m_ReplaceBall = false; bool m_MultiBall = false; bool m_KrakenAttack = false; + bool m_BallStuck = false; double m_KrakenCharge = 0; double m_KrakenStrength = 0; double m_PlayerStrength = 0; float m_Edge = 2.8f; Components::Transform* m_Transform = nullptr; Components::Pad* m_Pad = nullptr; + std::shared_ptr m_StickTransform; + std::shared_ptr m_StickyAim; bool m_Pause = false; @@ -94,6 +100,7 @@ private: dd::EventRelay m_EStageCleared; dd::EventRelay m_EPause; dd::EventRelay m_EKrakenAttack; + dd::EventRelay m_EStickyPad; dd::EventRelay m_EActionButton; bool OnKeyDown(const dd::Events::KeyDown &event); @@ -103,6 +110,7 @@ private: bool OnStageCleared(const dd::Events::StageCleared &event); bool OnPause(const dd::Events::Pause &event); bool OnKrakenAttack(const dd::Events::KrakenAttack &event); + bool OnStickyPad(const dd::Events::StickyPad &event); bool OnActionButton(const dd::Events::ActionButton &event); class PadSteeringInputController; diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index 6195c63..7959507 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -195,11 +195,14 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID } if (ballComponent != nullptr) { - auto transform = m_World->GetComponent(entity); - glm::vec2 dir = glm::normalize(glm::vec2(transform->Velocity.x, transform->Velocity.y)); - glm::vec2 up = glm::vec2(0.f, 1.f); - float angle = glm::acos(glm::dot(dir, up)) * glm::sign(dir.x); - transform->Orientation = glm::rotate(glm::quat(), angle, glm::vec3(0.f, 0.f, -1.f)); + if (!ballComponent->Sticky) + { + auto transform = m_World->GetComponent(entity); + glm::vec2 dir = glm::normalize(glm::vec2(transform->Velocity.x, transform->Velocity.y)); + glm::vec2 up = glm::vec2(0.f, 1.f); + float angle = glm::acos(glm::dot(dir, up)) * glm::sign(dir.x); + transform->Orientation = glm::rotate(glm::quat(), angle, glm::vec3(0.f, 0.f, -1.f)); + } } } @@ -458,7 +461,6 @@ bool dd::Systems::BallSystem::OnInkBlasterOver(const dd::Events::InkBlasterOver 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; diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index 93f6c93..700c4e0 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -200,21 +200,28 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe auto cBrick = m_World->GetComponent(brick); auto model = m_World->GetComponent(brick); if (typeInt == StandardBrick) { + cBrick->Type = StandardBrick; + auto type = m_World->AddComponent(brick); model->Color = colorVec; } else if (typeInt == MultiBallBrick) { cBrick->Type = MultiBallBrick; + auto type = m_World->AddComponent(brick); model->ModelFile = "Models/Brick/IceBrick.obj"; } else if (typeInt == LifebuoyBrick) { cBrick->Type = LifebuoyBrick; + auto type = m_World->AddComponent(brick); model->ModelFile = "Models/Brick/LifeBuoyBrick.obj"; } else if (typeInt == StickyBrick) { cBrick->Type = StickyBrick; + auto type = m_World->AddComponent(brick); model->ModelFile = "Models/Brick/StickyBrick.obj"; } else if (typeInt == InkBlasterBrick) { cBrick->Type = InkBlasterBrick; + auto type = m_World->AddComponent(brick); model->Color = glm::vec4(0.1f, 0.1f, 0.1f, 1.0f); } else if (typeInt == KrakenAttackBrick) { cBrick->Type = KrakenAttackBrick; + auto type = m_World->AddComponent(brick); model->Color = glm::vec4(0.f, 0.5f, 1.0f, .0f); } diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp index 9067ddb..5d24c8d 100755 --- a/src/game/Game/PadSystem.cpp +++ b/src/game/Game/PadSystem.cpp @@ -29,6 +29,7 @@ void dd::Systems::PadSystem::Initialize() EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared); EVENT_SUBSCRIBE_MEMBER(m_EPause, &PadSystem::OnPause); EVENT_SUBSCRIBE_MEMBER(m_EKrakenAttack, &PadSystem::OnKrakenAttack); + EVENT_SUBSCRIBE_MEMBER(m_EStickyPad, &PadSystem::OnStickyPad); EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &PadSystem::OnActionButton); //EVENT_SUBSCRIBE_MEMBER(m_EBindKey, &PadSystem::OnBindKey); @@ -53,6 +54,21 @@ void dd::Systems::PadSystem::Initialize() SetEdge(3.2 - (ctransform->Scale.x / 2)); } + + //Stick + { + auto ent = m_World->CreateEntity(); + m_World->SetProperty(ent, "Name", "Stick"); + std::shared_ptr transform = m_World->AddComponent(ent); + transform->Position = glm::vec3(30.f, 0.f, -10.f); + transform->Scale = glm::vec3(0.1f, 20.f, 0.1f); + std::shared_ptr sprite = m_World->AddComponent(ent); + sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; + std::shared_ptr sticky = m_World->AddComponent(ent); + m_World->CommitEntity(ent); + + m_StickTransform = transform; + } } void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -63,9 +79,21 @@ void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID p 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; + auto ballTransform = m_World->GetComponent(entity); + ballTransform->Position = Transform()->Position; + ballTransform->Position += ball->StickyPlacement; + glm::vec2 dir = glm::normalize(glm::vec2(ball->SavedSpeed.x, ball->SavedSpeed.y)); + glm::vec2 up = glm::vec2(0.f, 1.f); + float angle = glm::acos(glm::dot(dir, up)) * glm::sign(dir.x); + ballTransform->Orientation = glm::rotate(glm::quat(), angle, glm::vec3(0.f, 0.f, -1.f)); + /*if (m_StickyAim->Aiming) { + m_StickTransform->Orientation = glm::rotate(glm::quat(), angle, glm::vec3(0.f, 0.f, 1.f)); + m_StickTransform->Position = ballTransform->Position; + }*/ + } else { + /*if (!m_StickyAim->Aiming) { + m_StickTransform->Position = glm::vec3(30.f, 0.f, 0.f); + }*/ } } } @@ -181,7 +209,15 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) { } else if (val == GLFW_KEY_S) { Events::StageCleared e; EventBroker->Publish(e); - } else if (val == GLFW_KEY_K) { + } else if (val == GLFW_KEY_Y) { + Events::StickyPad e; + EventBroker->Publish(e); + } + else if (val == GLFW_KEY_I) { + Events::InkBlaster e; + EventBroker->Publish(e); + } + else if (val == GLFW_KEY_K) { Events::KrakenAttack e; e.ChargeUpdate = 0; e.KrakenStrength = 0.1; @@ -333,6 +369,11 @@ bool dd::Systems::PadSystem::OnKrakenAttack(const dd::Events::KrakenAttack &even return true; } +bool dd::Systems::PadSystem::OnStickyPad(const dd::Events::StickyPad &event) +{ + return true; +} + bool dd::Systems::PadSystem::OnActionButton(const dd::Events::ActionButton &event) { if (m_KrakenAttack) {