2018-03-19 08:31:45 -05:00
|
|
|
#include "Arduino.h"
|
|
|
|
|
#define FRICTION 1
|
|
|
|
|
|
|
|
|
|
class Particle
|
|
|
|
|
{
|
|
|
|
|
public:
|
2026-03-15 22:35:00 +01:00
|
|
|
void Spawn(int pos, int life, int aging_speed, const int color[3]);
|
2018-03-19 08:31:45 -05:00
|
|
|
void Tick(int USE_GRAVITY);
|
|
|
|
|
void Kill();
|
|
|
|
|
bool Alive();
|
|
|
|
|
int _pos;
|
|
|
|
|
int _power;
|
2026-03-15 22:35:00 +01:00
|
|
|
int _color[3];
|
2018-03-19 08:31:45 -05:00
|
|
|
private:
|
|
|
|
|
int _life;
|
|
|
|
|
int _alive;
|
|
|
|
|
int _sp;
|
2026-03-15 22:35:00 +01:00
|
|
|
int _aging;
|
2018-03-19 08:31:45 -05:00
|
|
|
};
|
|
|
|
|
|
2026-03-15 22:35:00 +01:00
|
|
|
void Particle::Spawn(int pos, int life, int aging_speed, const int color[3]){
|
2018-03-19 08:31:45 -05:00
|
|
|
_pos = pos;
|
2026-03-15 22:35:00 +01:00
|
|
|
_sp = random(-life, life);
|
2018-03-19 08:31:45 -05:00
|
|
|
_power = 255;
|
|
|
|
|
_alive = 1;
|
2026-03-15 22:35:00 +01:00
|
|
|
_life = life - abs(_sp);
|
|
|
|
|
_aging = aging_speed;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i< 3; i++) _color[i] = color[i];
|
2018-03-19 08:31:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Particle::Tick(int USE_GRAVITY){
|
|
|
|
|
if(_alive){
|
|
|
|
|
_life ++;
|
|
|
|
|
if(_sp > 0){
|
|
|
|
|
_sp -= _life/10;
|
|
|
|
|
}else{
|
|
|
|
|
_sp += _life/10;
|
|
|
|
|
}
|
|
|
|
|
if(USE_GRAVITY && _pos > 500) _sp -= 10;
|
2026-03-15 22:35:00 +01:00
|
|
|
_power = 100 - _aging*_life;
|
2018-03-19 08:31:45 -05:00
|
|
|
if(_power <= 0){
|
|
|
|
|
Kill();
|
|
|
|
|
}else{
|
|
|
|
|
_pos += _sp/7.0;
|
|
|
|
|
if(_pos > 1000){
|
|
|
|
|
_pos = 1000;
|
|
|
|
|
_sp = 0-(_sp/2);
|
|
|
|
|
}
|
|
|
|
|
else if(_pos < 0){
|
|
|
|
|
_pos = 0;
|
|
|
|
|
_sp = 0-(_sp/2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Particle::Alive(){
|
|
|
|
|
return _alive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Particle::Kill(){
|
|
|
|
|
_alive = 0;
|
|
|
|
|
}
|