Update 'sample/PGEX_SMX_Example.cpp'

timelimit
sigonasr2 2 weeks ago
parent 1de7d840aa
commit c6202ccf86
  1. 218
      sample/PGEX_SMX_Example.cpp

@ -24,180 +24,112 @@ public:
return true;
}
struct Snow{
vf2d pos;
int id;
};
struct ExpandCircle{
vi2d pos;
float radius;
Pixel col;
};
std::vector<Snow>snow;
std::vector<Snow>backgroundSnow;
std::vector<ExpandCircle>expandCircles;
const float backgroundSnowInterval{0.1f};
float backgroundSnowIntervalTimer{backgroundSnowInterval};
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{0.};
float fallSpd{6.f};
float snowAmplitude{2.f};
std::map<std::pair<Key,int>,float>recreateCircleTimer{};
const float recreateCircleInterval{0.25f};
uint64_t SNOW_ID{0U};
struct Pad{
int consecutiveNotesHit{0}; //Once more than 100 are hit in a row, we're online.
float lastNoteHit{0.f}; //Amount of time that passed since the last note was hit. If this goes above ten seconds, reset consectiveNotesHit.
float idleTime{0.f}; //Timer that determines if the pad has been in an idle state long enough to issue a warning.
bool alertActive{false}; //Turns on when the alert sound should be played. Sets back to false when idle time is reset.
}
Pad p1,p2;
bool OnUserUpdate(float fElapsedTime) override
{
Clear({0,0,32});
backgroundSnowIntervalTimer-=fElapsedTime;
snowTimer-=fElapsedTime;
snowIntervalTimer-=fElapsedTime;
for(auto&[KEY,time]:recreateCircleTimer){
recreateCircleTimer[KEY]-=fElapsedTime;
}
if(snowTimer<=0.f){
snow.emplace_back(vf2d{util::random(ScreenWidth()),-2.f},SNOW_ID++);
snowTimer=snowInterval;
}
if(backgroundSnowIntervalTimer<=0.f){
int xOffset{int(util::random(ScreenWidth()))};
if(backgroundSnowDirection==RIGHT){
xOffset-=ScreenWidth()/2;
}else{
xOffset+=ScreenWidth()/2;
}
backgroundSnow.emplace_back(vf2d{float(xOffset),-2.f},SNOW_ID++);
backgroundSnowIntervalTimer=backgroundSnowInterval;
}
if(snowIntervalTimer<=0.f){
snowInterval=util::random_range(0.1f,2.f);
backgroundSnowDirection=!RIGHT;
if(rand()%2==0)backgroundSnowDirection=RIGHT;
snowIntervalTimer=snowIntervalChangeInterval;
}
for(Snow&backSnow:backgroundSnow){
srand(backSnow.id);
if(backgroundSnowDirection==RIGHT){
backSnow.pos.x+=fElapsedTime*snowAmplitude;
}else{
backSnow.pos.x-=fElapsedTime*snowAmplitude;
}
backSnow.pos.y+=fallSpd*fElapsedTime/2.f;
uint8_t randCol{uint8_t(10+rand()%50)};
Draw(backSnow.pos,Pixel{randCol,randCol,randCol});
}
for(Snow&snow:snow){
srand(snow.id);
float fallSpdMult{(rand()%25)/100.f};
snow.pos.y+=(fallSpd*(1.f-fallSpdMult))*fElapsedTime;
FillCircle(vi2d{int(snow.pos.x+sin(totalElapsedTime+snow.id*0.5f*fallSpd)*snowAmplitude),int(snow.pos.y)},rand()%2+1,{uint8_t(150+rand()%105),uint8_t(190+rand()%65),uint8_t(190+rand()%65)});
}
Clear({0,0,0});
SetPixelMode(Pixel::ALPHA);
for(ExpandCircle&circle:expandCircles){
circle.radius+=fallSpd*fElapsedTime*6;
DrawCircle(circle.pos,circle.radius,circle.col);
p1.lastNoteHit+=fElapsedTime;
p2.lastNoteHit+=fElapsedTime;
p1.idleTime+=fElapsedTime;
p2.idleTime+=fElapsedTime;
FillRect({0,0},{12,21},{32,0,32,64});
FillRect({12,0},{12,21},{0,32,32,64});
if(p1.idleTime>=120.f){
//Over the next 40 seconds, the outline of the pad will slowly enclose in.
const float timeRatio{(160.f-p1.idleTime)/40.f};
DrawRect({0,0},{int(12),int(11*timeRatio)},{255,0,0,uint8_t(timeRatio*255)}) //Top
DrawRect({0,int(21-11*timeRatio)},{int(12),int(11*timeRatio)},{255,0,0,uint8_t(timeRatio*255)}) //Bottom
DrawRect({0,0},{int(6*timeRatio),int(21)},{255,0,0,uint8_t(timeRatio*255)}) //Left
DrawRect({int(12-6*timeRatio),0},{int(6*timeRatio),int(21)},{255,0,0,uint8_t(timeRatio*255)}) //Right
}
if(p2.idleTime>=120.f){
//Over the next 40 seconds, the outline of the pad will slowly enclose in.
const float timeRatio{(160.f-p2.idleTime)/40.f};
DrawRect({12,0},{int(12),int(11*timeRatio)},{255,0,0,uint8_t(timeRatio*255)}) //Top
DrawRect({12,int(21-11*timeRatio)},{int(12),int(11*timeRatio)},{255,0,0,uint8_t(timeRatio*255)}) //Bottom
DrawRect({12,0},{int(6*timeRatio),int(21)},{255,0,0,uint8_t(timeRatio*255)}) //Left
DrawRect({12+int(12-6*timeRatio),0},{int(6*timeRatio),int(21)},{255,0,0,uint8_t(timeRatio*255)}) //Right
}
std::erase_if(snow,[this](const Snow&snow){return snow.pos.y>ScreenHeight()+2;});
std::erase_if(backgroundSnow,[this](const Snow&backSnow){return backSnow.pos.y>ScreenHeight()+2;});
std::erase_if(expandCircles,[this](const ExpandCircle&circle){return circle.radius>24+2;});
double previousTotalElapsedTime{totalElapsedTime};
totalElapsedTime=fmod(totalElapsedTime+fElapsedTime,10000.);
#undef RIGHT
if(smx.GetPanel(RIGHT,0).bHeld){
FillRect({8,7},{3,6},{VERY_DARK_MAGENTA.r,VERY_DARK_MAGENTA.g,VERY_DARK_MAGENTA.b,64});
DrawRect({8,7},{3,6},VERY_DARK_MAGENTA);
if(recreateCircleTimer[{RIGHT,0}]<=0.f){
expandCircles.emplace_back(vi2d{8+1,7+3},1,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
expandCircles.emplace_back(vi2d{8+1,7+3},0.5f,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
expandCircles.emplace_back(vi2d{8+1,7+3},0.f,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
recreateCircleTimer[{RIGHT,0}]=recreateCircleInterval;
}
}else recreateCircleTimer[{RIGHT,0}]=0;
}
if(smx.GetPanel(UP,0).bHeld){
FillRect({4,0},{3,6},{VERY_DARK_MAGENTA.r,VERY_DARK_MAGENTA.g,VERY_DARK_MAGENTA.b,64});
DrawRect({4,0},{3,6},VERY_DARK_MAGENTA);
if(recreateCircleTimer[{UP,0}]<=0.f){
expandCircles.emplace_back(vi2d{4+1,0+3},1,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
expandCircles.emplace_back(vi2d{4+1,0+3},0.5f,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
expandCircles.emplace_back(vi2d{4+1,0+3},0.f,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
recreateCircleTimer[{UP,0}]=recreateCircleInterval;
}
}else recreateCircleTimer[{UP,0}]=0;
}
if(smx.GetPanel(DOWN,0).bHeld){
FillRect({4,14},{3,6},{VERY_DARK_MAGENTA.r,VERY_DARK_MAGENTA.g,VERY_DARK_MAGENTA.b,64});
DrawRect({4,14},{3,6},VERY_DARK_MAGENTA);
if(recreateCircleTimer[{DOWN,0}]<=0.f){
expandCircles.emplace_back(vi2d{4+1,14+3},1,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
expandCircles.emplace_back(vi2d{4+1,14+3},0.5f,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
expandCircles.emplace_back(vi2d{4+1,14+3},0.f,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
recreateCircleTimer[{DOWN,0}]=recreateCircleInterval;
}
}else recreateCircleTimer[{DOWN,0}]=0;
}
if(smx.GetPanel(LEFT,0).bHeld){
FillRect({0,7},{3,6},{VERY_DARK_MAGENTA.r,VERY_DARK_MAGENTA.g,VERY_DARK_MAGENTA.b,64});
DrawRect({0,7},{3,6},VERY_DARK_MAGENTA);
if(recreateCircleTimer[{LEFT,0}]<=0.f){
expandCircles.emplace_back(vi2d{0+1,7+3},1,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
expandCircles.emplace_back(vi2d{0+1,7+3},0.5f,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
expandCircles.emplace_back(vi2d{0+1,7+3},0.f,Pixel{DARK_MAGENTA.r,DARK_MAGENTA.g,DARK_MAGENTA.b,64});
recreateCircleTimer[{LEFT,0}]=recreateCircleInterval;
}
}else recreateCircleTimer[{LEFT,0}]=0;
}
if(smx.GetPanel(RIGHT,1).bHeld){
FillRect({20,7},{3,6},{VERY_DARK_CYAN.r,VERY_DARK_CYAN.g,VERY_DARK_CYAN.b,64});
DrawRect({20,7},{3,6},VERY_DARK_CYAN);
if(recreateCircleTimer[{RIGHT,1}]<=0.f){
expandCircles.emplace_back(vi2d{20+1,7+3},1,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
expandCircles.emplace_back(vi2d{20+1,7+3},0.5f,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
expandCircles.emplace_back(vi2d{20+1,7+3},0.f,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
recreateCircleTimer[{RIGHT,1}]=recreateCircleInterval;
}
}else recreateCircleTimer[{RIGHT,1}]=0;
}
if(smx.GetPanel(UP,1).bHeld){
FillRect({16,0},{3,6},{VERY_DARK_CYAN.r,VERY_DARK_CYAN.g,VERY_DARK_CYAN.b,64});
DrawRect({16,0},{3,6},VERY_DARK_CYAN);
if(recreateCircleTimer[{UP,1}]<=0.f){
expandCircles.emplace_back(vi2d{16+1,3+3},1,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
expandCircles.emplace_back(vi2d{16+1,3+3},0.5f,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
expandCircles.emplace_back(vi2d{16+1,3+3},0.f,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
recreateCircleTimer[{UP,1}]=recreateCircleInterval;
}
}else recreateCircleTimer[{UP,1}]=0;
}
if(smx.GetPanel(DOWN,1).bHeld){
FillRect({16,14},{3,6},{VERY_DARK_CYAN.r,VERY_DARK_CYAN.g,VERY_DARK_CYAN.b,64});
DrawRect({16,14},{3,6},VERY_DARK_CYAN);
if(recreateCircleTimer[{DOWN,1}]<=0.f){
expandCircles.emplace_back(vi2d{16+1,14+3},1,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
expandCircles.emplace_back(vi2d{16+1,14+3},0.5f,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
expandCircles.emplace_back(vi2d{16+1,14+3},0.f,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
recreateCircleTimer[{DOWN,1}]=recreateCircleInterval;
}
}else recreateCircleTimer[{DOWN,1}]=0;
}
if(smx.GetPanel(LEFT,1).bHeld){
FillRect({12,7},{3,6},{VERY_DARK_CYAN.r,VERY_DARK_CYAN.g,VERY_DARK_CYAN.b,64});
DrawRect({12,7},{3,6},VERY_DARK_CYAN);
if(recreateCircleTimer[{LEFT,1}]<=0.f){
expandCircles.emplace_back(vi2d{12+1,3+3},1,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
expandCircles.emplace_back(vi2d{12+1,3+3},0.5f,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
expandCircles.emplace_back(vi2d{12+1,3+3},0.f,Pixel{DARK_CYAN.r,DARK_CYAN.g,DARK_CYAN.b,64});
recreateCircleTimer[{LEFT,1}]=recreateCircleInterval;
}
}else recreateCircleTimer[{LEFT,1}]=0;
}
if(smx.GetPanel(RIGHT,0).bReleased||smx.GetPanel(LEFT,0).bReleased||smx.GetPanel(UP,0).bReleased||smx.GetPanel(DOWN,0).bReleased){
p1.consecutiveNotesHit++;
p1.lastNoteHit=0.f;
}
if(smx.GetPanel(RIGHT,1).bReleased||smx.GetPanel(LEFT,1).bReleased||smx.GetPanel(UP,1).bReleased||smx.GetPanel(DOWN,1).bReleased){
p2.consecutiveNotesHit++;
p2.lastNoteHit=0.f;
}
if(p1.lastNoteHit>=10.f){
p1.consectiveNotesHit=0;
}
if(p2.lastNoteHit>=10.f){
p2.consectiveNotesHit=0;
}
if(p1.consectiveNotesHit>=100){
p1.idleTime=0.f;
p1.alertActive=false;
}
if(p2.consectiveNotesHit>=100){
p2.idleTime=0.f;
p2.alertActive=false;
}
if(p1.idleTime>=160.f){
p1.alertActive=true;
//PLAY SOUND HERE!!
}
if(p2.idleTime>=160.f){
p2.alertActive=true;
//PLAY SOUND HERE!!
}
SetPixelMode(Pixel::MASK);

Loading…
Cancel
Save