generated from sigonasr2/CPlusPlusProjectTemplate
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.6 KiB
96 lines
2.6 KiB
#ifndef PARTICLE_H
|
|
#include "pixelGameEngine.h"
|
|
#include "defines.h"
|
|
using namespace olc;
|
|
#define PARTICLE_H
|
|
|
|
class Particle{
|
|
public:
|
|
vd2d pos;
|
|
vd2d spd;
|
|
vd2d acc;
|
|
int lifetime; //In frames.
|
|
bool wrap;
|
|
Particle(vd2d pos,vd2d spd,vd2d acc,int lifetime,bool wrap=false)
|
|
:pos(pos),spd(spd),acc(acc),lifetime(lifetime){};
|
|
virtual void render(PixelGameEngine*game)=0;
|
|
virtual void particleUpdate()=0;
|
|
bool update() {
|
|
spd+=acc;
|
|
pos+=spd;
|
|
if (wrap) {
|
|
if (pos.x<0) {
|
|
pos.x+=WIDTH;
|
|
} else
|
|
if (pos.y<0) {
|
|
pos.y+=HEIGHT;
|
|
}
|
|
if (pos.x>WIDTH) {
|
|
pos.x-=WIDTH;
|
|
} else
|
|
if (pos.y>HEIGHT) {
|
|
pos.y-=HEIGHT;
|
|
}
|
|
}
|
|
lifetime--;
|
|
return lifetime>0;
|
|
}
|
|
vd2d GetPos() {
|
|
return pos;
|
|
}
|
|
vd2d GetSpd() {
|
|
return spd;
|
|
}
|
|
vd2d GetAcc() {
|
|
return acc;
|
|
}
|
|
void SetPos(vd2d pos) {
|
|
this->pos=pos;
|
|
}
|
|
};
|
|
|
|
class LineParticle:public Particle{
|
|
public:
|
|
Pixel col;
|
|
LineParticle(vd2d pos,vd2d spd,vd2d acc,int lifetime,Pixel col=WHITE,bool wrap=false)
|
|
:col(col),Particle(pos,spd,acc,lifetime,wrap){}
|
|
void particleUpdate()override{}
|
|
void render(PixelGameEngine*game)override{
|
|
game->DrawLineDecal(pos,pos+spd,col);
|
|
}
|
|
};
|
|
|
|
class SquareParticle:public Particle{
|
|
private:
|
|
vd2d size;
|
|
public:
|
|
Pixel col;
|
|
SquareParticle(vd2d pos,vd2d size,vd2d spd,vd2d acc,int lifetime,Pixel col=WHITE,bool wrap=false)
|
|
:col(col),size(size),Particle(pos,spd,acc,lifetime,wrap){}
|
|
void particleUpdate()override{}
|
|
void render(PixelGameEngine*game)override{
|
|
game->FillRectDecal(pos,size,col);
|
|
}
|
|
};
|
|
|
|
class WaterParticle:public Particle{
|
|
private:
|
|
vd2d size;
|
|
vd2d PickRandomSpd() {
|
|
return {rand()%60/10.0F-3,-rand()%100/10.0F-2};
|
|
}
|
|
public:
|
|
Pixel col;
|
|
WaterParticle(vd2d pos,vd2d size,vd2d acc,int lifetime,Pixel col=WHITE)
|
|
:col(col),size(size),Particle(pos,PickRandomSpd(),acc,lifetime){}
|
|
void particleUpdate()override{
|
|
if (this->pos.y>HEIGHT) {
|
|
this->spd=PickRandomSpd();
|
|
this->pos={WIDTH/2,HEIGHT};
|
|
}
|
|
}
|
|
void render(PixelGameEngine*game)override{
|
|
game->FillRectDecal(pos,size,col);
|
|
}
|
|
};
|
|
#endif |