2021-03-22 23:56:29 +00:00
|
|
|
//
|
|
|
|
// Created by SeanOMik on 3/21/2021.
|
|
|
|
// Github: https://github.com/SeanOMik
|
|
|
|
// Email: seanomik@gmail.com
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SIMPLEENGINE_PARTICLE_EMITTER_H
|
|
|
|
#define SIMPLEENGINE_PARTICLE_EMITTER_H
|
|
|
|
|
|
|
|
#include "../event.h"
|
|
|
|
#include "particle_property.h"
|
2021-03-30 00:52:27 +00:00
|
|
|
#include "particle_emitter_property.h"
|
2021-03-22 23:56:29 +00:00
|
|
|
#include "particle.h"
|
|
|
|
#include "../random.h"
|
|
|
|
#include "../range_2.h"
|
|
|
|
|
|
|
|
#include <SFML/Graphics/Rect.hpp>
|
|
|
|
#include <SFML/Graphics/RectangleShape.hpp>
|
|
|
|
#include <SFML/Graphics/Sprite.hpp>
|
|
|
|
#include <SFML/System/Clock.hpp>
|
|
|
|
|
|
|
|
#include <SFML/System/Vector2.hpp>
|
|
|
|
|
|
|
|
namespace simpleengine {
|
|
|
|
namespace particle {
|
|
|
|
struct ParticleAttributes {
|
|
|
|
uint32_t lifetime_ms;
|
|
|
|
sf::Vector2f start_velocity;
|
|
|
|
float rotation_velocity = 0;
|
|
|
|
sf::Vector2f scale = sf::Vector2f(1, 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParticleEmitter : public simpleengine::Event {
|
|
|
|
protected:
|
2021-03-30 00:52:27 +00:00
|
|
|
using ParticlePropertyPtr = std::unique_ptr<simpleengine::particle::ParticleProperty>;
|
2021-03-22 23:56:29 +00:00
|
|
|
using ParticlePropertyVector = std::vector<ParticlePropertyPtr>;
|
2021-03-30 00:52:27 +00:00
|
|
|
|
|
|
|
using EmitterPropertyPtr = std::unique_ptr<simpleengine::particle::ParticleEmitterProperty>;
|
|
|
|
using EmitterPropertyVector = std::vector<EmitterPropertyPtr>;
|
2021-03-22 23:56:29 +00:00
|
|
|
public:
|
2021-03-30 00:52:27 +00:00
|
|
|
ParticleEmitter(sf::Texture& texture, sf::Vector2f position, double emit_variance, uint32_t emit_count, uint32_t particle_count, Range2f particle_range, ParticleAttributes attributes, ParticlePropertyVector& particle_properties, EmitterPropertyVector& emitter_properties);
|
2021-03-22 23:56:29 +00:00
|
|
|
|
2021-03-30 00:52:27 +00:00
|
|
|
void SetProperties(ParticlePropertyVector particle_properties);
|
2021-03-22 23:56:29 +00:00
|
|
|
|
2021-03-23 00:54:32 +00:00
|
|
|
virtual void Update(const float& delta_time) override;
|
|
|
|
virtual void Render(sf::RenderTarget* target) override;
|
2021-03-22 23:56:29 +00:00
|
|
|
protected:
|
|
|
|
sf::Texture& texture;
|
|
|
|
sf::Vector2f position;
|
|
|
|
double emit_variance;
|
|
|
|
uint32_t emit_count;
|
|
|
|
uint32_t particle_count;
|
|
|
|
Range2f particle_range;
|
|
|
|
ParticleAttributes attributes;
|
2021-03-30 00:52:27 +00:00
|
|
|
ParticlePropertyVector& particle_properties;
|
|
|
|
EmitterPropertyVector& emitter_properties;
|
2021-03-22 23:56:29 +00:00
|
|
|
|
|
|
|
std::vector<simpleengine::particle::Particle> particles;
|
|
|
|
sf::Clock time;
|
|
|
|
simpleengine::Random<double> random;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //SIMPLEENGINE_PARTICLE_EMITTER_H
|