From 3814c2593138858ffa7c099366e5f06866db2449 Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Wed, 7 Oct 2015 17:09:55 +0200 Subject: [PATCH] Squid does not move until space is pressed. Experimenting with scroll. This shouldn't really be committed, but Visual Studio. --- include/Core/CTransform.h | 3 +++ include/Core/Engine.h | 16 +++++++++++++++ include/Game/BallSystem.h | 6 +++++- include/Game/CBall.h | 1 + include/Game/EActionButton.h | 25 ++++++++++++++++++++++ include/Game/EStageCleared.h | 3 ++- include/Game/PadSystem.h | 1 + src/game/Game/BallSystem.cpp | 33 +++++++++++++++++++++++++----- src/game/Game/LevelSystem.cpp | 15 ++++++++++++++ src/game/Game/PadSystem.cpp | 8 ++++++-- src/game/Physics/PhysicsSystem.cpp | 8 +++++++- 11 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 include/Game/EActionButton.h diff --git a/include/Core/CTransform.h b/include/Core/CTransform.h index 06cbe5c..e99f21e 100644 --- a/include/Core/CTransform.h +++ b/include/Core/CTransform.h @@ -41,6 +41,9 @@ struct Transform : public Component glm::vec3 Velocity; /** Physical scale multiplier. */ glm::vec3 Scale; + + // Sticky is if it sticks with the player or not. True means it will follow the camera. + bool Sticky; }; } diff --git a/include/Core/Engine.h b/include/Core/Engine.h index cdcc756..63228f5 100755 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -168,11 +168,22 @@ public: auto transform = m_World->AddComponent(t_halfPipe); transform->Position = glm::vec3(0.f, 0.f, -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(1.f, 0.f, 0.f, 0.3f); m_World->CommitEntity(t_halfPipe); } + /*{ + auto t_halfPipe = m_World->CreateEntity(); + auto transform = m_World->AddComponent(t_halfPipe); + transform->Position = glm::vec3(0.f, 6.f, -15.f); + transform->Scale = glm::vec3(6.f, 6.f, 10.f); + auto model = m_World->AddComponent(t_halfPipe); + model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj"; + model->Color = glm::vec4(1.f, 0.f, 0.f, 0.3f); + m_World->CommitEntity(t_halfPipe); + }*/ //Background { @@ -247,6 +258,7 @@ public: rectangleShape->Dimensions = glm::vec2(20.f, 0.5f); std::shared_ptr physics = m_World->AddComponent(BottomWall); physics->CollisionType = CollisionType::Type::Static; + transform->Sticky = true; m_World->CommitEntity(BottomWall); } @@ -266,6 +278,7 @@ public: physics->CollisionType = CollisionType::Type::Static; physics->Category = CollisionLayer::Wall; physics->Mask = static_cast(CollisionLayer::Ball | CollisionLayer::Brick); + transform->Sticky = true; m_World->CommitEntity(topWall); } @@ -287,6 +300,7 @@ public: physics->CollisionType = CollisionType::Type::Static; physics->Category = CollisionLayer::Wall; physics->Mask = static_cast(CollisionLayer::Ball | CollisionLayer::Brick); + transform->Sticky = true; m_World->CommitEntity(leftWall); } @@ -308,6 +322,8 @@ public: physics->CollisionType = CollisionType::Type::Static; physics->Category = CollisionLayer::Wall; physics->Mask = static_cast(CollisionLayer::Ball | CollisionLayer::Brick); + transform->Sticky = true; + m_World->CommitEntity(rightWall); } diff --git a/include/Game/BallSystem.h b/include/Game/BallSystem.h index db1ab66..01f5cc5 100644 --- a/include/Game/BallSystem.h +++ b/include/Game/BallSystem.h @@ -25,6 +25,7 @@ #include "Game/EPause.h" #include "Game/EHitPad.h" #include "Game/EHitLag.h" +#include "Game/EActionButton.h" namespace dd { @@ -89,6 +90,7 @@ private: int m_PastLives = 3; bool m_ReplaceBall = false; bool m_Pause = false; + bool m_Waiting = true; EntityID m_LastCollision = 999999; glm::vec3 m_SavedSpeed; @@ -104,7 +106,8 @@ private: dd::EventRelay m_EResetBall; dd::EventRelay m_EMultiBall; dd::EventRelay m_EPause; - EventRelay m_Contact; + dd::EventRelay m_Contact; + dd::EventRelay m_EActionButton; bool Contact(const Events::Contact &event); bool OnLifeLost(const dd::Events::LifeLost &event); @@ -112,6 +115,7 @@ private: bool OnResetBall(const dd::Events::ResetBall &event); bool OnMultiBall(const dd::Events::MultiBall &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 fbf720a..0330ed9 100644 --- a/include/Game/CBall.h +++ b/include/Game/CBall.h @@ -19,6 +19,7 @@ struct Ball : Component float Speed = 5.f; int Combo = 0; bool Paused = false; + bool Waiting = true; glm::vec3 SavedSpeed = glm::vec3(0, 0, 0); }; diff --git a/include/Game/EActionButton.h b/include/Game/EActionButton.h new file mode 100644 index 0000000..fc387c8 --- /dev/null +++ b/include/Game/EActionButton.h @@ -0,0 +1,25 @@ +// +// Created by Administrator on 2015-10-07. +// + +#ifndef DAYDREAM_EACTIONBUTTON_H +#define DAYDREAM_EACTIONBUTTON_H + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Events +{ + +struct ActionButton : Event +{ + +}; + +} + +} + +#endif //DAYDREAM_EACTIONBUTTON_H diff --git a/include/Game/EStageCleared.h b/include/Game/EStageCleared.h index 29ef021..82d3a5e 100644 --- a/include/Game/EStageCleared.h +++ b/include/Game/EStageCleared.h @@ -13,7 +13,8 @@ namespace Events { struct StageCleared : Event { - + int StageCleared = 0; + int StageCluster = 0; }; } } diff --git a/include/Game/PadSystem.h b/include/Game/PadSystem.h index 39a2582..3cb8360 100755 --- a/include/Game/PadSystem.h +++ b/include/Game/PadSystem.h @@ -30,6 +30,7 @@ #include "Game/EStageCleared.h" #include "Game/EPause.h" #include "Game/EHitLag.h" +#include "Game/EActionButton.h" namespace dd diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index 4c624f2..f515c8e 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -19,6 +19,7 @@ void dd::Systems::BallSystem::Initialize() EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &BallSystem::OnResetBall); EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall); EVENT_SUBSCRIBE_MEMBER(m_EPause, &BallSystem::OnPause); + EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &BallSystem::OnActionButton); //OctoBall { @@ -33,12 +34,14 @@ void dd::Systems::BallSystem::Initialize() circleShape->Radius = 0.4f; std::shared_ptr ball = m_World->AddComponent(ent); ball->Speed = 5.f; + ball->Waiting = true; std::shared_ptr physics = m_World->AddComponent(ent); std::shared_ptr ballTemplate = m_World->AddComponent(ent); - physics->CollisionType = CollisionType::Type::Dynamic; + physics->CollisionType = CollisionType::Type::Dynamic; physics->Category = CollisionLayer::Type::Ball; physics->Mask = static_cast(CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall); physics->Calculate = true; + transform->Sticky = true; //auto plight = m_World->AddComponent(ent); //plight->Radius = 2.f; @@ -100,12 +103,23 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID if (templateCheck != nullptr){ return; } if (ballComponent != nullptr) { + 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 { + 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); + transform->Orientation = glm::quat(); + return; + } + } if (ReplaceBall()) { SetReplaceBall(false); - - auto transform = m_World->GetComponent(entity); - transform->Position = glm::vec3(0.0f, 0.26f, -10.f); - transform->Velocity = glm::vec3(0.0f, -ballComponent->Speed, 0.f); + m_Waiting = true; + ballComponent->Waiting = true; } auto transformBall = m_World->GetComponent(entity); @@ -324,6 +338,7 @@ void dd::Systems::BallSystem::CreateLife(int number) std::shared_ptr transform = m_World->AddComponent(life); transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f); transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f); + transform->Sticky = true; std::shared_ptr lifeNr = m_World->AddComponent(life); lifeNr->Number = number; @@ -367,6 +382,8 @@ bool dd::Systems::BallSystem::OnMultiBall(const dd::Events::MultiBall &event) auto transform2 = m_World->GetComponent(ent2); auto ball1 = m_World->GetComponent(ent1); auto ball2 = m_World->GetComponent(ent2); + ball1->Waiting = false; + ball2->Waiting = false; auto padTransform = event.padTransform; float x1 = padTransform->Position.x - 2, x2 = padTransform->Position.x + 2; if (x1 < -m_EdgeX) { @@ -386,3 +403,9 @@ bool dd::Systems::BallSystem::OnMultiBall(const dd::Events::MultiBall &event) return true; } +bool dd::Systems::BallSystem::OnActionButton(const dd::Events::ActionButton &event) +{ + m_Waiting = false; + return true; +} + diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index ed7f6bd..26b18a6 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -31,6 +31,7 @@ void dd::Systems::LevelSystem::Initialize() cPhys->GravityScale = 0.f; cPhys->Category = CollisionLayer::Type::Brick; cPhys->Mask = CollisionLayer::Type::Ball; + transform->Sticky = false; model->ModelFile = "Models/Brick/TurquoiseBrick.obj"; transform->Position = glm::vec3(50, 50, -10); @@ -61,6 +62,17 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID auto templateCheck = m_World->GetComponent(entity); if (templateCheck != nullptr){ return; } + // Check the background. + auto model = m_World->GetComponent(entity); + if (model != nullptr) { + if (model->ModelFile == "Models/Test/halfpipe/Halfpipe.obj") { + auto transform = m_World->GetComponent(entity); + if (transform->Position.y <= -12) { + transform->Position.y = 12; + } + } + } + auto brick = m_World->GetComponent(entity); if (brick != nullptr) { auto transform = m_World->GetComponent(entity); @@ -81,6 +93,8 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID if (NumberOfBricks() <= 0 && m_LooseBricks <= 0 && !Restarting()) { if (MultiBalls() <= 0 && PowerUps() <= 0) { Events::StageCleared ec; + ec.StageCleared = m_CurrentLevel; + ec.StageCluster = m_CurrentCluster; EventBroker->Publish(ec); } else { if (ball != nullptr && MultiBalls() > 0) { @@ -304,6 +318,7 @@ bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp & cPhys->CollisionType = CollisionType::Type::Dynamic; cPhys->Category = CollisionLayer::Type::PowerUp; cPhys->Mask = CollisionLayer::Type::Pad; + transform->Sticky = false; std::shared_ptr cPow = m_World->AddComponent(powerUp); diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp index bd06e5d..55a69ad 100755 --- a/src/game/Game/PadSystem.cpp +++ b/src/game/Game/PadSystem.cpp @@ -28,6 +28,7 @@ void dd::Systems::PadSystem::Initialize() EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp); EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared); EVENT_SUBSCRIBE_MEMBER(m_EPause, &PadSystem::OnPause); + //EVENT_SUBSCRIBE_MEMBER(m_EBindKey, &PadSystem::OnBindKey); { auto ent = m_World->CreateEntity(); @@ -41,6 +42,7 @@ void dd::Systems::PadSystem::Initialize() physics->Category = CollisionLayer::Type::Pad; physics->Mask = static_cast(CollisionLayer::Ball | CollisionLayer::PowerUp); physics->Calculate = true; + ctransform->Sticky = true; auto cModel = m_World->AddComponent(ent); cModel->ModelFile = "Models/Submarine2.obj"; @@ -123,8 +125,7 @@ bool dd::Systems::PadSystem::OnPause(const dd::Events::Pause &event) return true; } -bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) -{ +bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) { int val = event.KeyCode; if (val == GLFW_KEY_UP) { //std::cout << "Up!" << std::endl; @@ -154,6 +155,9 @@ 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) { + Events::ActionButton e; + EventBroker->Publish(e); } else if (val == GLFW_KEY_D) { return false; } diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp index 8496a1f..ae44247 100755 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -194,7 +194,13 @@ void dd::Systems::PhysicsSystem::Update(double dt) void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { - + auto transform = m_World->GetComponent(entity); + if (transform != nullptr) { + if (transform->Sticky == true) { + return; + } + transform->Position.y -= 1.0f * dt; + } } bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)