Random direction upon ResetBall, turn in direction.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#ifndef DAYDREAM_BALLSYSTEM_H
|
#ifndef DAYDREAM_BALLSYSTEM_H
|
||||||
#define DAYDREAM_BALLSYSTEM_H
|
#define DAYDREAM_BALLSYSTEM_H
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
@@ -99,6 +101,8 @@ public:
|
|||||||
void SetPause(const bool& pause) { m_Pause = pause; }
|
void SetPause(const bool& pause) { m_Pause = pause; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::mt19937 m_RandomGenerator;
|
||||||
|
|
||||||
float m_XMovementMultiplier = 2.f;
|
float m_XMovementMultiplier = 2.f;
|
||||||
float m_EdgeX = 3.4f; //Actually 3.2, but anyways.
|
float m_EdgeX = 3.4f; //Actually 3.2, but anyways.
|
||||||
float m_EdgeY = 5.2f;
|
float m_EdgeY = 5.2f;
|
||||||
@@ -118,6 +122,8 @@ private:
|
|||||||
int m_StickyCounter = 3;
|
int m_StickyCounter = 3;
|
||||||
bool m_GodMode = false;
|
bool m_GodMode = false;
|
||||||
|
|
||||||
|
bool m_First = true;
|
||||||
|
|
||||||
bool m_StageBlockedWaiting = false;
|
bool m_StageBlockedWaiting = false;
|
||||||
|
|
||||||
glm::vec3 m_SavedSpeed;
|
glm::vec3 m_SavedSpeed;
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ private:
|
|||||||
bool m_Initialized = false;
|
bool m_Initialized = false;
|
||||||
bool m_Pause = false;
|
bool m_Pause = false;
|
||||||
int m_LooseBricks = 0;
|
int m_LooseBricks = 0;
|
||||||
int m_CurrentCluster = 1;
|
int m_CurrentCluster = 0;
|
||||||
int m_CurrentLevel = 1;
|
int m_CurrentLevel = 1;
|
||||||
int m_MultiBalls = 0;
|
int m_MultiBalls = 0;
|
||||||
int m_PowerUps = 0;
|
int m_PowerUps = 0;
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ void dd::Systems::BallSystem::RegisterComponents(ComponentFactory *cf)
|
|||||||
|
|
||||||
void dd::Systems::BallSystem::Initialize()
|
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_Contact, &BallSystem::Contact);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, &BallSystem::OnLifeLost);
|
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, &BallSystem::OnLifeLost);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &BallSystem::OnMultiBallLost);
|
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->Position = glm::vec3(-20.f, 0.26f, -10.f);
|
||||||
transform->Scale = glm::vec3(0.3f, 0.3f, 0.3f);
|
transform->Scale = glm::vec3(0.3f, 0.3f, 0.3f);
|
||||||
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
|
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
|
||||||
|
transform->Orientation = glm::quat();
|
||||||
auto model = m_World->AddComponent<Components::Model>(ent);
|
auto model = m_World->AddComponent<Components::Model>(ent);
|
||||||
model->ModelFile = "Models/Sid/Sid.dae";
|
model->ModelFile = "Models/Sid/Sid.dae";
|
||||||
auto animation = m_World->AddComponent<Components::Animation>(ent);
|
auto animation = m_World->AddComponent<Components::Animation>(ent);
|
||||||
@@ -69,13 +71,14 @@ void dd::Systems::BallSystem::Initialize()
|
|||||||
CreateLife(i);
|
CreateLife(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetReplaceBall(true);
|
||||||
|
|
||||||
m_GodMode = ResourceManager::Load<ConfigFile>("Config.ini")->GetValue<bool>("Cheat.GodMode", false);
|
m_GodMode = ResourceManager::Load<ConfigFile>("Config.ini")->GetValue<bool>("Cheat.GodMode", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::BallSystem::Update(double dt)
|
void dd::Systems::BallSystem::Update(double dt)
|
||||||
{
|
{
|
||||||
if (Lives() == 0)
|
if (Lives() == 0) {
|
||||||
{
|
|
||||||
if (m_KrakenAttack) {
|
if (m_KrakenAttack) {
|
||||||
Events::KrakenAttackEnd e;
|
Events::KrakenAttackEnd e;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
@@ -133,7 +136,11 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
if (ReplaceBall()) {
|
if (ReplaceBall()) {
|
||||||
SetReplaceBall(false);
|
SetReplaceBall(false);
|
||||||
m_Waiting = true;
|
m_Waiting = true;
|
||||||
|
std::uniform_real_distribution<float> dist(-0.5f, 0.5f);
|
||||||
|
float random = dist(m_RandomGenerator);
|
||||||
|
ballComponent->SavedSpeed = glm::vec3(random, 1, 0.f);
|
||||||
ballComponent->Waiting = true;
|
ballComponent->Waiting = true;
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ballComponent->Waiting) {
|
if (ballComponent->Waiting) {
|
||||||
@@ -141,12 +148,17 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
m_Restarting = false;
|
m_Restarting = false;
|
||||||
ballComponent->Waiting = false;
|
ballComponent->Waiting = false;
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
transform->Velocity = glm::normalize(glm::vec3(0.5f, 1, 0.f)) * ballComponent->Speed;
|
/*std::uniform_real_distribution<float> dist(-0.5f, 0.5f);
|
||||||
|
float random = dist(m_RandomGenerator);*/
|
||||||
|
transform->Velocity = glm::normalize(ballComponent->SavedSpeed) * ballComponent->Speed;
|
||||||
} else if (!ballComponent->Sticky) {
|
} else if (!ballComponent->Sticky) {
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
|
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
|
||||||
//transform->Position = glm::vec3(0.0f, -3.f, -10.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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user