From 1a6f18da94d70354c11697fba4aea3765451b27d Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Wed, 21 Oct 2015 16:53:04 +0200 Subject: [PATCH] Random direction upon ResetBall, turn in direction. --- include/Game/BallSystem.h | 6 ++++++ include/Game/LevelSystem.h | 2 +- src/game/Game/BallSystem.cpp | 22 +++++++++++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/Game/BallSystem.h b/include/Game/BallSystem.h index ddee3fd..46e50ef 100644 --- a/include/Game/BallSystem.h +++ b/include/Game/BallSystem.h @@ -1,6 +1,8 @@ #ifndef DAYDREAM_BALLSYSTEM_H #define DAYDREAM_BALLSYSTEM_H +#include + #include "Core/System.h" #include "Core/World.h" #include "Core/EventBroker.h" @@ -99,6 +101,8 @@ public: void SetPause(const bool& pause) { m_Pause = pause; } private: + std::mt19937 m_RandomGenerator; + float m_XMovementMultiplier = 2.f; float m_EdgeX = 3.4f; //Actually 3.2, but anyways. float m_EdgeY = 5.2f; @@ -118,6 +122,8 @@ private: int m_StickyCounter = 3; bool m_GodMode = false; + bool m_First = true; + bool m_StageBlockedWaiting = false; glm::vec3 m_SavedSpeed; diff --git a/include/Game/LevelSystem.h b/include/Game/LevelSystem.h index cc5d75c..95a3397 100755 --- a/include/Game/LevelSystem.h +++ b/include/Game/LevelSystem.h @@ -144,7 +144,7 @@ private: bool m_Initialized = false; bool m_Pause = false; int m_LooseBricks = 0; - int m_CurrentCluster = 1; + int m_CurrentCluster = 0; int m_CurrentLevel = 1; int m_MultiBalls = 0; int m_PowerUps = 0; diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index a6c509e..31377f1 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -12,7 +12,8 @@ void dd::Systems::BallSystem::RegisterComponents(ComponentFactory *cf) void dd::Systems::BallSystem::Initialize() { - + std::random_device rd; + m_RandomGenerator = std::mt19937(rd()); EVENT_SUBSCRIBE_MEMBER(m_Contact, &BallSystem::Contact); EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, &BallSystem::OnLifeLost); EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &BallSystem::OnMultiBallLost); @@ -37,6 +38,7 @@ void dd::Systems::BallSystem::Initialize() transform->Position = glm::vec3(-20.f, 0.26f, -10.f); transform->Scale = glm::vec3(0.3f, 0.3f, 0.3f); transform->Velocity = glm::vec3(0.f, 0.f, 0.f); + transform->Orientation = glm::quat(); auto model = m_World->AddComponent(ent); model->ModelFile = "Models/Sid/Sid.dae"; auto animation = m_World->AddComponent(ent); @@ -69,13 +71,14 @@ void dd::Systems::BallSystem::Initialize() CreateLife(i); } + SetReplaceBall(true); + m_GodMode = ResourceManager::Load("Config.ini")->GetValue("Cheat.GodMode", false); } void dd::Systems::BallSystem::Update(double dt) { - if (Lives() == 0) - { + if (Lives() == 0) { if (m_KrakenAttack) { Events::KrakenAttackEnd e; EventBroker->Publish(e); @@ -133,7 +136,11 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID if (ReplaceBall()) { SetReplaceBall(false); m_Waiting = true; + std::uniform_real_distribution dist(-0.5f, 0.5f); + float random = dist(m_RandomGenerator); + ballComponent->SavedSpeed = glm::vec3(random, 1, 0.f); ballComponent->Waiting = true; + auto transform = m_World->GetComponent(entity); } if (ballComponent->Waiting) { @@ -141,12 +148,17 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID m_Restarting = false; ballComponent->Waiting = false; auto transform = m_World->GetComponent(entity); - transform->Velocity = glm::normalize(glm::vec3(0.5f, 1, 0.f)) * ballComponent->Speed; + /*std::uniform_real_distribution dist(-0.5f, 0.5f); + float random = dist(m_RandomGenerator);*/ + transform->Velocity = glm::normalize(ballComponent->SavedSpeed) * ballComponent->Speed; } 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); - transform->Orientation = glm::quat(); + if (m_First) { + transform->Orientation = glm::quat(); + m_First = false; + } return; } }