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.
78 lines
1.7 KiB
78 lines
1.7 KiB
#define OLC_PGE_APPLICATION
|
|
#include "pixelGameEngine.h"
|
|
#include "Smoke.h"
|
|
|
|
using namespace olc;
|
|
|
|
class Example : public PixelGameEngine
|
|
{
|
|
public:
|
|
std::vector<Smoke> smokeParticles;
|
|
float lastCreationTime=0;
|
|
Example()
|
|
{
|
|
sAppName = "Example";
|
|
}
|
|
|
|
public:
|
|
|
|
float range(float low, float high) {
|
|
return rand()%10000/10000.f*(high-low)+(low);
|
|
}
|
|
|
|
bool OnUserCreate() override
|
|
{
|
|
// Called once at the start, so create things here
|
|
int smokeCount=200;
|
|
int RANDOM_SPREAD_VAL=10; //Spread out between this amount;
|
|
for (int i=0;i<smokeCount;i++) {
|
|
smokeParticles.push_back(
|
|
/*Size*/{{2,range(0.5,1)},
|
|
/*Position*/{range(100,100+RANDOM_SPREAD_VAL)-RANDOM_SPREAD_VAL/2,range(100,102)}
|
|
,/*Rise Speed*/range(1,3),/*Fade Speed*/range(60,100)});
|
|
}
|
|
|
|
for (int i=0;i<smokeCount;i++) {
|
|
smokeParticles.push_back(
|
|
/*Size*/{{2,range(0.5,1)},
|
|
/*Position*/{range(200,202) , range(100,102)}
|
|
,/*Rise Speed*/range(0.5,1.5),/*Fade Speed*/range(100,200)});
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override
|
|
{
|
|
for (int i=0;i<smokeParticles.size();i++) {
|
|
smokeParticles[i].update(fElapsedTime);
|
|
smokeParticles[i].render(this);
|
|
|
|
if (smokeParticles[i].expired()) {
|
|
smokeParticles.erase(smokeParticles.begin()+i--);
|
|
}
|
|
}
|
|
|
|
lastCreationTime+=fElapsedTime;
|
|
if (lastCreationTime>0.2) {
|
|
|
|
for (int i=0;i<10;i++) {
|
|
smokeParticles.push_back(
|
|
/*Size*/{{5,range(2,5)},
|
|
/*Position*/{range(175,225) , range(100,102)}
|
|
,/*Rise Speed*/range(1,2.5),/*Fade Speed*/range(30,50)});
|
|
}
|
|
lastCreationTime-=0.2;
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
|
|
|
|
int main()
|
|
{
|
|
Example demo;
|
|
if (demo.Construct(256, 240, 4, 4))
|
|
demo.Start();
|
|
|
|
return 0;
|
|
}
|
|
|