// // Created by SeanOMik on 3/22/2021. // Github: https://github.com/SeanOMik // Email: seanomik@gmail.com // #ifndef SIMPLEENGINE_RANDOM_LIFETIME_PROPERTY_H #define SIMPLEENGINE_RANDOM_LIFETIME_PROPERTY_H #include "../particle_property.h" #include "../../range.h" #include "../../random.h" #include "../particle.h" #include #include #include #include namespace simpleengine { namespace particle { class RandomLifetimeParticleProperty : public ParticleProperty { public: template RandomLifetimeParticleProperty(std::chrono::duration min, std::chrono::duration max) : range(Range( std::chrono::duration_cast(min), std::chrono::duration_cast(max))) { } template RandomLifetimeParticleProperty(const simpleengine::Range>& range) : RandomLifetimeParticleProperty(range.min, range.max) { } RandomLifetimeParticleProperty(const RandomLifetimeParticleProperty& other) { this->range = other.range; } std::unique_ptr Clone() const override { return std::make_unique(range); } void OnParticleSpawn(simpleengine::particle::Particle& particle) override { simpleengine::Random rand; int lifetime = rand.NextInRange(range.min.count(), range.max.count()); particle.SetLifetime(std::chrono::milliseconds(lifetime)); //std::cout << "Lifetime: " << lifetime << "ms" << std::endl; } void Update(simpleengine::particle::Particle& particle) override { } private: simpleengine::Range range; }; } } #endif //SIMPLEENGINE_RANDOM_LIFETIME_PROPERTY_H