... even more event-based
This commit is contained in:
@@ -8,7 +8,7 @@ void Systems::ParticleSystem::Initialize()
|
|||||||
{
|
{
|
||||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||||
tempSpawnedExplosions = false;
|
tempSpawnedExplosions = false;
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &ParticleSystem::OnKeyUp);
|
EVENT_SUBSCRIBE_MEMBER(m_EExplosion, &ParticleSystem::CreateExplosion);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::ParticleSystem::Update(double dt)
|
void Systems::ParticleSystem::Update(double dt)
|
||||||
@@ -225,15 +225,15 @@ void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vect
|
|||||||
alpha = spectrum[0] + dAlpha * timeProgress;
|
alpha = spectrum[0] + dAlpha * timeProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::ParticleSystem::CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale)
|
bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e)
|
||||||
{
|
{
|
||||||
auto explosion = m_World->CreateEntity();
|
auto explosion = m_World->CreateEntity();
|
||||||
auto emitter = m_World->AddComponent<Components::ParticleEmitter>(explosion);
|
auto emitter = m_World->AddComponent<Components::ParticleEmitter>(explosion);
|
||||||
emitter->LifeTime = _lifeTime;
|
emitter->LifeTime = e.LifeTime;
|
||||||
emitter->SpawnCount = _particlesToSpawn;
|
emitter->SpawnCount = e.ParticlesToSpawn;
|
||||||
emitter->Speed = _speed;
|
emitter->Speed = e.Speed;
|
||||||
emitter->SpreadAngle = _spreadAngle;
|
emitter->SpreadAngle = e.SpreadAngle;
|
||||||
emitter->SpawnFrequency = _lifeTime + 20; //temp
|
emitter->SpawnFrequency = e.LifeTime + 20; //temp
|
||||||
// emitter->UseGoalVelocity = true;
|
// emitter->UseGoalVelocity = true;
|
||||||
// emitter->GoalVelocity = glm::vec3(0,-_speed, 0);
|
// emitter->GoalVelocity = glm::vec3(0,-_speed, 0);
|
||||||
m_World->CommitEntity(explosion);
|
m_World->CommitEntity(explosion);
|
||||||
@@ -242,36 +242,16 @@ void Systems::ParticleSystem::CreateExplosion(glm::vec3 _pos, double _lifeTime,
|
|||||||
auto TEMP = m_World->AddComponent<Components::Transform>(particleEnt);
|
auto TEMP = m_World->AddComponent<Components::Transform>(particleEnt);
|
||||||
TEMP->Scale = glm::vec3(0);
|
TEMP->Scale = glm::vec3(0);
|
||||||
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEnt);
|
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEnt);
|
||||||
spriteComponent->SpriteFile = _spritePath;
|
spriteComponent->SpriteFile = e.spritePath;
|
||||||
m_World->CommitEntity(particleEnt);
|
m_World->CommitEntity(particleEnt);
|
||||||
emitter->ParticleTemplate = particleEnt;
|
emitter->ParticleTemplate = particleEnt;
|
||||||
|
|
||||||
auto transform = m_World->AddComponent<Components::Transform>(explosion);
|
auto transform = m_World->AddComponent<Components::Transform>(explosion);
|
||||||
transform->Position = _pos;
|
transform->Position = e.Position;
|
||||||
transform->Orientation = _relativeUpOri;
|
transform->Orientation = e.RelativeUpOrientation;
|
||||||
|
|
||||||
SpawnParticles(explosion);
|
SpawnParticles(explosion);
|
||||||
m_ExplosionEmitters[explosion] = glfwGetTime();
|
m_ExplosionEmitters[explosion] = glfwGetTime();
|
||||||
}
|
|
||||||
|
|
||||||
bool Systems::ParticleSystem::OnKeyUp(const Events::KeyUp &e)
|
|
||||||
{
|
|
||||||
if(!tempSpawnedExplosions)
|
|
||||||
{
|
|
||||||
if (e.KeyCode == GLFW_KEY_B)
|
|
||||||
{
|
|
||||||
tempSpawnedExplosions = true;
|
|
||||||
CreateExplosion(
|
|
||||||
glm::vec3(0, 10, 0),
|
|
||||||
0.5,
|
|
||||||
60,
|
|
||||||
"Textures/Sprites/NewtonTreeDeleteASAPPlease.png",
|
|
||||||
glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0)),
|
|
||||||
40,
|
|
||||||
glm::pi<float>(),
|
|
||||||
0.5f
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "Components/Sprite.h"
|
#include "Components/Sprite.h"
|
||||||
#include "EventBroker.h"
|
#include "EventBroker.h"
|
||||||
#include "Events/KeyUp.h"
|
#include "Events/KeyUp.h"
|
||||||
|
#include "Events/CreateExplosion.h"
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ public:
|
|||||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
|
|
||||||
void CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale);
|
//void CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale);
|
||||||
|
|
||||||
virtual bool OnCommand(const Events::KeyUp &event) { return false; }
|
virtual bool OnCommand(const Events::KeyUp &event) { return false; }
|
||||||
|
|
||||||
@@ -54,8 +55,10 @@ private:
|
|||||||
|
|
||||||
bool tempSpawnedExplosions;
|
bool tempSpawnedExplosions;
|
||||||
|
|
||||||
EventRelay<ParticleSystem, Events::KeyUp> m_EKeyUp;
|
// EventRelay<ParticleSystem, Events::KeyUp> m_EKeyUp;
|
||||||
bool OnKeyUp(const Events::KeyUp &e);
|
// bool OnKeyUp(const Events::KeyUp &e);
|
||||||
|
EventRelay<ParticleSystem, Events::CreateExplosion> m_EExplosion;
|
||||||
|
bool CreateExplosion(const Events::CreateExplosion &e);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user