2021-03-22 23:56:29 +00:00
|
|
|
//
|
|
|
|
// Created by SeanOMik on 3/22/2021.
|
|
|
|
// Github: https://github.com/SeanOMik
|
|
|
|
// Email: seanomik@gmail.com
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SIMPLEENGINE_RANDOM_VELOCITY_PROPERTY_H
|
|
|
|
#define SIMPLEENGINE_RANDOM_VELOCITY_PROPERTY_H
|
|
|
|
|
|
|
|
#include "../particle_property.h"
|
|
|
|
#include "../../range_2.h"
|
|
|
|
#include "../../random.h"
|
|
|
|
#include "../particle.h"
|
|
|
|
|
2021-03-30 00:52:27 +00:00
|
|
|
#include <random>
|
|
|
|
#include <iostream>
|
|
|
|
|
2021-03-22 23:56:29 +00:00
|
|
|
namespace simpleengine {
|
|
|
|
namespace particle {
|
|
|
|
class RandomVelocityParticleProperty : public ParticleProperty {
|
|
|
|
public:
|
2021-03-30 00:52:27 +00:00
|
|
|
RandomVelocityParticleProperty(const simpleengine::Range2f& range) : range(range) {
|
2021-03-22 23:56:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-23 00:54:32 +00:00
|
|
|
RandomVelocityParticleProperty(float min_x, float max_x, float min_y, float max_y)
|
|
|
|
: RandomVelocityParticleProperty(Range2f(min_x, max_x, min_y, max_y)) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-30 00:52:27 +00:00
|
|
|
RandomVelocityParticleProperty(const RandomVelocityParticleProperty& other) {
|
|
|
|
this->range = other.range;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<ParticleProperty> Clone() const override {
|
|
|
|
return std::make_unique<RandomVelocityParticleProperty>(range);
|
|
|
|
}
|
|
|
|
|
2021-03-22 23:56:29 +00:00
|
|
|
void OnParticleSpawn(simpleengine::particle::Particle& particle) override {
|
2021-03-30 00:52:27 +00:00
|
|
|
simpleengine::Random<float, std::random_device, std::mt19937_64> rand;
|
2021-03-22 23:56:29 +00:00
|
|
|
sf::Vector2f velocity;
|
2021-03-30 00:52:27 +00:00
|
|
|
velocity.x = rand.NextInRange<std::uniform_real_distribution<float>>(range.min_x, range.max_x);
|
|
|
|
velocity.y = rand.NextInRange<std::uniform_real_distribution<float>>(range.min_y, range.max_y);
|
2021-03-22 23:56:29 +00:00
|
|
|
|
|
|
|
particle.velocity = velocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update(simpleengine::particle::Particle& particle) override {
|
|
|
|
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
simpleengine::Range2f range;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //SIMPLEENGINE_RANDOM_VELOCITY_PROPERTY_H
|