SMX_PGE/sample/PGEX_SMX_Example.cpp

83 lines
2.0 KiB
C++
Raw Normal View History

2023-06-16 18:51:30 -05:00
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
2023-06-16 19:33:55 -05:00
#include "PGEX_SMX.h"
2024-11-26 22:51:23 -06:00
#include "util.h"
2023-06-16 18:51:30 -05:00
using namespace olc;
2017-12-14 20:02:36 -06:00
2023-06-16 18:51:30 -05:00
class SMX_PGE : public olc::PixelGameEngine
2017-12-14 20:02:36 -06:00
{
2023-06-16 19:33:55 -05:00
PGEX_SMX smx;
2023-06-16 18:44:07 -07:00
bool paused = false;
int mode = 0;
vf2d playerPos = { 0,0 };
2017-12-14 20:02:36 -06:00
public:
2023-06-16 18:51:30 -05:00
SMX_PGE()
2017-12-14 20:02:36 -06:00
{
2023-06-16 19:33:55 -05:00
sAppName = "SMX PGE";
2017-12-14 20:02:36 -06:00
}
2023-06-16 18:51:30 -05:00
public:
bool OnUserCreate() override
2017-12-14 20:02:36 -06:00
{
2023-06-16 18:51:30 -05:00
// Called once at the start, so create things here
return true;
}
2017-12-14 20:02:36 -06:00
2024-11-26 22:51:23 -06:00
std::vector<vf2d>snow;
std::vector<vf2d>backgroundSnow;
float backgroundSnowIntervalTimer{0.03f};
float backgroundSnowDirectionInterval{60.f};
#define RIGHT true
bool backgroundSnowDirection{RIGHT};
float snowInterval{0.8f};
float snowTimer{snowInterval};
const float snowIntervalChangeInterval{60.f};
float snowIntervalTimer{snowIntervalChangeInterval};
double totalElapsedTime{};
float fallSpd{6.f};
float snowAmplitude{2.f};
2023-06-16 18:51:30 -05:00
bool OnUserUpdate(float fElapsedTime) override
{
2024-11-26 22:51:23 -06:00
Clear({0,0,32});
backgroundSnowIntervalTimer-=fElapsedTime;
snowTimer-=fElapsedTime;
snowIntervalTimer-=fElapsedTime;
if(snowTimer<=0.f){
snow.emplace_back(util::random(ScreenWidth()),-2.f);
snowTimer=snowInterval;
}
if(backgroundSnowIntervalTimer<=0.f){
backgroundSnowIntervalTimer=snowIntervalTimer*26.66666667f;
2023-06-16 18:44:07 -07:00
}
2024-11-26 22:51:23 -06:00
if(snowIntervalTimer<=0.f){
snowInterval=util::random_range(0.1f,2.f);
snowIntervalTimer=snowIntervalChangeInterval;
2023-06-16 18:44:07 -07:00
}
2024-11-26 22:51:23 -06:00
for(int ind{0};vf2d&snow:snow){
snow.y+=fallSpd*fElapsedTime;
srand(ind);
FillCircle(vi2d{int(snow.x+sin(totalElapsedTime+ind*0.5f*fallSpd)*snowAmplitude),int(snow.y)},rand()%2+1,{uint8_t(200+rand()%55),uint8_t(235+rand()%20),255});
ind++;
}
totalElapsedTime=fmod(totalElapsedTime+fElapsedTime,10000.);
2023-06-16 18:51:30 -05:00
return true;
2017-12-14 20:02:36 -06:00
}
};
2023-06-16 18:51:30 -05:00
2017-12-14 20:02:36 -06:00
int main()
{
2023-06-16 18:51:30 -05:00
SMX_PGE demo;
2024-11-26 22:51:23 -06:00
if (demo.Construct(24, 21, 50, 50))
2023-06-16 18:51:30 -05:00
demo.Start();
2017-12-14 20:02:36 -06:00
return 0;
}