generated from sigonasr2/CPlusPlusProjectTemplate
Effect particle system implemented
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
d457d88258
commit
1d45800bfd
Binary file not shown.
33
effect.h
Normal file
33
effect.h
Normal file
@ -0,0 +1,33 @@
|
||||
class Effect{
|
||||
public:
|
||||
std::vector<Particle*> particles;
|
||||
virtual void create(std::vector<Particle*>&PARTICLES)=0;
|
||||
virtual bool update()=0;
|
||||
Effect(){}
|
||||
void render(PixelGameEngine*game) {
|
||||
for (int i=0;i<particles.size();i++) {
|
||||
particles[i]->render(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<Particle*>&PARTICLES){
|
||||
lifetime=maxLifeTime;
|
||||
for (int i=0;i<fountainDensity;i++) {
|
||||
PARTICLES.push_back(new WaterParticle({WIDTH/2,HEIGHT},{rand()%3+1,rand()%3+1},{0,rand()%10/10.0F+0.1F},lifetime,Pixel(rand()%128,rand()%128,255)));
|
||||
}
|
||||
}
|
||||
bool update()override{
|
||||
lifetime--;
|
||||
return lifetime>0;
|
||||
}
|
||||
};
|
||||
|
||||
FountainEffect*FOUNTAIN_EFFECT;
|
34
main.cpp
34
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<Particle*> 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;i<PARTICLES.size();i++) {
|
||||
PARTICLES[i]->update();
|
||||
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;i<PARTICLES.size();i++) {
|
||||
delete PARTICLES[i];
|
||||
}
|
||||
PARTICLES.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (GetCurrentCutsceneAction()!=ActionType::NONE) {
|
||||
CurrentAction=GetCurrentCutsceneAction();
|
||||
@ -910,6 +925,10 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
ConsoleShow(F1,false);
|
||||
}
|
||||
|
||||
if (GetKey(O).bPressed) {
|
||||
StartEffect(FOUNTAIN_EFFECT);
|
||||
}
|
||||
|
||||
if (BATTLE_ENCOUNTER!=nullptr&&!messageBoxVisible) {
|
||||
switch (BATTLE_STATE) {
|
||||
case BattleState::SELECT_ACTION:{
|
||||
@ -3171,6 +3190,11 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
vi2d grid(int x, int y) {
|
||||
return {x*32,y*32};
|
||||
}
|
||||
|
||||
void StartEffect(Effect*eff) {
|
||||
CURRENT_EFFECT=eff;
|
||||
eff->create(PARTICLES);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
38
particle.h
38
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;
|
||||
@ -51,3 +53,37 @@ class LineParticle:public Particle{
|
||||
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);
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user