Particle system started

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent ca4134fbb9
commit d457d88258
  1. BIN
      C++ProjectTemplate
  2. 10
      defines.h
  3. 28
      main.cpp
  4. 53
      particle.h

Binary file not shown.

@ -0,0 +1,10 @@
#define WIDTH 256
#define HEIGHT 224
#define TILEMAP_SIZE_X 512
#define TILEMAP_SIZE_Y 512
#define TILEMAP_EDITOR_DRAW_MULT 0.4375
#define TILEMAP_EDITOR_TILESIZE (32*TILEMAP_EDITOR_DRAW_MULT)
#define PARTY_TRAIL_LENGTH 48
#define CAMERA_WAIT_TIME 60
#define HEALTH_ROLLING_SPEED 2

@ -3,6 +3,7 @@
#define OLC_PGEX_SPLASHSCREEN
#include "splash.h"
#define OLC_SOUNDWAVE
#include "defines.h"
#include "soundwaveEngine.h"
#include "tiles.h"
#include "references.h"
@ -11,16 +12,7 @@
#include <assert.h>
#include "cutscene.h"
#include "encounters.h"
#define WIDTH 256
#define HEIGHT 224
#define TILEMAP_SIZE_X 512
#define TILEMAP_SIZE_Y 512
#define TILEMAP_EDITOR_DRAW_MULT 0.4375
#define TILEMAP_EDITOR_TILESIZE (32*TILEMAP_EDITOR_DRAW_MULT)
#define PARTY_TRAIL_LENGTH 48
#define CAMERA_WAIT_TIME 60
#define HEALTH_ROLLING_SPEED 2
#include "particle.h"
#define ㅎ
#define ㅍ
@ -540,6 +532,8 @@ public:
std::map<std::string,Animation*> ANIMATIONS;
std::map<int,Object*> OBJ_INFO;
std::vector<Particle*> PARTICLES;
bool OnUserCreate() override
{
srand(time(NULL));
@ -602,6 +596,10 @@ 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;
}
@ -668,6 +666,11 @@ 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();
PARTICLES[i]->particleUpdate();
}
if (GetCurrentCutsceneAction()!=ActionType::NONE) {
CurrentAction=GetCurrentCutsceneAction();
CurrentCutscene->LockAction();
@ -1572,6 +1575,9 @@ goes on a very long time, I hope you can understand this is only for testing pur
DrawStringPropDecal({6,6},messageBoxText);
}
SetDrawTarget(layer::INTERFACE);
for (int i=0;i<PARTICLES.size();i++) {
PARTICLES[i]->render(this);
}
FillRectDecal({0,0},{WIDTH,HEIGHT},Pixel(0,0,0,(int)CUTSCENE_FADE_VALUE));
};
@ -1614,7 +1620,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
pixelOffsetY=0;
}
SetDrawTarget(layer::DYNAMIC);
DrawPartialDecal(obj->GetPos()-cameraPos,obj->spr->spr,{(float)((obj->frameIndex%obj->spr->frames)*obj->spr->width),0},{(float)obj->spr->width,(float)obj->spr->spr->sprite->height},obj->GetScale(),Pixel(obj->color.r,obj->color.g,obj->color.b,abs(sin(M_PI/60*frameCount)*210)));
DrawPartialDecal(obj->GetPos()-cameraPos,obj->spr->spr,{(float)((obj->frameIndex%obj->spr->frames)*obj->spr->width),0},{(float)obj->spr->width,(float)obj->spr->spr->sprite->height},obj->GetScale(),obj->color);
} else {
SetDrawTarget(layer::DYNAMIC);
DrawPartialDecal(obj->GetPos()-cameraPos,obj->spr->spr,{(float)((obj->frameIndex%obj->spr->frames)*obj->spr->width),0},{(float)obj->spr->width,(float)obj->spr->spr->sprite->height},obj->GetScale(),obj->color);

@ -0,0 +1,53 @@
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);
}
};
Loading…
Cancel
Save