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.
54 lines
1.5 KiB
54 lines
1.5 KiB
|
|
#include "pixelGameEngine.h"
|
|
#include <algorithm>
|
|
|
|
using namespace olc;
|
|
|
|
class Smoke{
|
|
float riseSpd;
|
|
std::vector<vf2d> points;
|
|
std::vector<vf2d> uvs;
|
|
std::vector<Pixel> cols;
|
|
vf2d size;
|
|
vf2d pos;
|
|
float fadeSpd=1; //How much alpha to drop down per second.
|
|
int freq=rand()%2+1;
|
|
float alpha=128;
|
|
public:
|
|
Smoke(vf2d size, vf2d pos, float riseSpd=5.f, float fadeSpd=100)
|
|
:size(size),riseSpd(riseSpd),fadeSpd(fadeSpd) {
|
|
int ind=0;
|
|
points.push_back({pos.x,pos.y});
|
|
uvs.push_back({0,0});
|
|
cols.push_back(Pixel(128,128,128,128));
|
|
for (float i=0;i<2*M_PI;i+=2*M_PI/64) {
|
|
points.push_back({sinf(i)*size.x+pos.x,cosf(i)*size.y+pos.y});
|
|
uvs.push_back({0,0});
|
|
cols.push_back(Pixel(128,128,128,128));
|
|
}
|
|
points.push_back(points[1]);
|
|
uvs.push_back({0,0});
|
|
cols.push_back(Pixel(128,128,128,128));
|
|
};
|
|
|
|
void update(float fElapsedTime) {
|
|
alpha=std::clamp(alpha-fadeSpd*fElapsedTime,0.f,255.f);
|
|
for (int i=0;i<points.size();i++) {
|
|
points[i].y-=(riseSpd+rand()%1000/1000.0F*riseSpd*4)*fElapsedTime;
|
|
cols[i].a=(int)alpha;
|
|
}
|
|
}
|
|
|
|
void render(PixelGameEngine*engine) {
|
|
engine->DrawPolygonDecal(nullptr,points,uvs,cols);
|
|
}
|
|
|
|
bool expired() {
|
|
for (int i=0;i<cols.size();i++) {
|
|
if (cols[i].a>0) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}; |