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.
SeasonI/particle.h

53 lines
1.4 KiB

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;
void 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;
}
}
}
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);
}
};