diff --git a/C++ProjectTemplate b/C++ProjectTemplate index e79c68e..fa20c88 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/effect.h b/effect.h new file mode 100644 index 0000000..b9017e8 --- /dev/null +++ b/effect.h @@ -0,0 +1,33 @@ +class Effect{ + public: + std::vector particles; + virtual void create(std::vector&PARTICLES)=0; + virtual bool update()=0; + Effect(){} + void render(PixelGameEngine*game) { + for (int i=0;irender(game); + } + } +}; + +class FountainEffect:public Effect{ + int fountainDensity=0; + int maxLifeTime=0; + int lifetime=0; + public: + FountainEffect(int fountainDensity,int lifetime) + :fountainDensity(fountainDensity),lifetime(lifetime),maxLifeTime(lifetime){} + void create(std::vector&PARTICLES){ + lifetime=maxLifeTime; + for (int i=0;i0; + } +}; + +FountainEffect*FOUNTAIN_EFFECT; \ No newline at end of file diff --git a/main.cpp b/main.cpp index 8f92505..9802f45 100644 --- a/main.cpp +++ b/main.cpp @@ -13,6 +13,7 @@ #include "cutscene.h" #include "encounters.h" #include "particle.h" +#include "effect.h" #define ㅎ #define ㅍ @@ -534,6 +535,8 @@ public: std::vector PARTICLES; + Effect*CURRENT_EFFECT=nullptr; + bool OnUserCreate() override { srand(time(NULL)); @@ -546,6 +549,8 @@ public: ConsoleCaptureStdOut(true); // Called once at the start, so create things here + FOUNTAIN_EFFECT = new FountainEffect(250,2000); + EnableLayer(layer::COLLISION,false); SetupMoveList(); @@ -596,10 +601,6 @@ in some form or capacity or another. Even though it goes on a very long time, I hope you can understand this is only for testing purposes! )");*/ - for (int i=0;i<1000;i++) { - PARTICLES.push_back(new LineParticle({rand()%WIDTH,rand()%HEIGHT},{rand()%10-5,rand()%10-5},{0,0},rand()%1000,Pixel(rand()%255,rand()%255,rand()%255),true)); - } - return true; } @@ -667,9 +668,23 @@ goes on a very long time, I hope you can understand this is only for testing pur } for (int i=0;iupdate(); + if (!PARTICLES[i]->update()) { + delete PARTICLES[i]; + PARTICLES.erase(PARTICLES.begin()+i); + i--; + continue; + } PARTICLES[i]->particleUpdate(); } + if (CURRENT_EFFECT!=nullptr) { + if (!CURRENT_EFFECT->update()) { + CURRENT_EFFECT=nullptr; + for (int i=0;icreate(PARTICLES); + } }; diff --git a/particle.h b/particle.h index 1a010f4..02bb815 100644 --- a/particle.h +++ b/particle.h @@ -9,7 +9,7 @@ class Particle{ :pos(pos),spd(spd),acc(acc),lifetime(lifetime){}; virtual void render(PixelGameEngine*game)=0; virtual void particleUpdate()=0; - void update() { + bool update() { spd+=acc; pos+=spd; if (wrap) { @@ -26,6 +26,8 @@ class Particle{ pos.y-=HEIGHT; } } + lifetime--; + return lifetime>0; } vd2d GetPos() { return pos; @@ -50,4 +52,38 @@ class LineParticle:public Particle{ 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); + } }; \ No newline at end of file