/**
* Triangles
* Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* This is based on a wiki entry
* https://github.com/SFML/SFML/wiki/Source:-Particle-System
*/
#pragma once
#include
#include
#include
#include
#include
#include
#include
#include
class Randomizer
{
public:
Randomizer() : device_(), engine_(device_()){};
int rnd(int a, int b) {
std::uniform_int_distribution uni_dist(a, b);
return uni_dist(engine_);
};
double rnd(double a, double b) {
std::uniform_real_distribution uni_dist(a, b);
return uni_dist(engine_);
};
private:
std::random_device device_;
std::default_random_engine engine_;
};
struct Particle
{
sf::Vector2f pos;
sf::Vector2f vel;
sf::Color color;
float transparency;
};
class ParticleSystem
{
public:
ParticleSystem( int width, int height );
~ParticleSystem();
void fuel(int particles, float angle);
void update(sf::Time delta);
void render();
void clear();
void setPosition(const sf::Vector2f position)
{
_position = position;
}
void setPosition(float x, float y)
{
setPosition(sf::Vector2f(x, y));
}
void setParticleSpeed(float particleSpeed)
{
_particleSpeed = particleSpeed;
}
void setDissolutionRate(float dissolutionRate)
{
_dissolutionRate = dissolutionRate;
}
const sf::Sprite& getSprite() const
{
return _sprite;
}
private:
sf::Vector2f _position; // Particle origin (pixel co-ordinates)
sf::Clock _clock; // Used to scale particle motion
sf::Color _transparent; // sf::Color( 0, 0, 0, 0 )
sf::Image _image; // See render() and remove()
sf::Texture _texture;
Randomizer _randomizer;
sf::Sprite _sprite; // Connected to m_image
float _particleSpeed;// Pixels per second (at most)
float _dissolutionRate;
std::vector _particles;
};