Add in break monitoring timer system to both pads.

timelimit
sigonasr2 2 weeks ago
parent d7813db36f
commit 566cbc59f6
  1. 142
      sample/PGEX_SMX_Example.cpp

@ -10,6 +10,7 @@ class SMX_PGE : public olc::PixelGameEngine
bool paused = false;
int mode = 0;
vf2d playerPos = { 0,0 };
bool enabled{true};
public:
SMX_PGE()
{
@ -27,9 +28,12 @@ public:
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.
float idleTime{120.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.
}
float flashTime{0.f}; //How much time has passed since the pad has flashed to a brighter/darker color.
bool flashRed{false}; //Set to true to choose the brighter red tone.
bool isActive{true};
};
Pad p1,p2;
@ -40,29 +44,92 @@ public:
SetPixelMode(Pixel::ALPHA);
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
#undef RIGHT
if(GetKey(HOME).bPressed)enabled=!enabled;
if(enabled){
p1.idleTime+=fElapsedTime;
p2.idleTime+=fElapsedTime;
if(p1.idleTime>=120.f&&p1.isActive){
//Over the next 40 seconds, the outline of the pad will slowly enclose in.
const float timeRatio{std::min(1.f-((160.f-p1.idleTime)/40.f),1.f)};
const uint8_t alpha{uint8_t(p1.flashRed?255:uint8_t(timeRatio*48))};
FillRect({0,0},{int(11),int(11*timeRatio)},{255,0,0,alpha}); //Top
FillRect({0,int(21-11*timeRatio+1)},{int(11),int(11*timeRatio)},{255,0,0,alpha}); //Bottom
FillRect({0,0},{int(6*timeRatio),int(21)},{255,0,0,alpha}); //Left
FillRect({int(12-6*timeRatio+1),0},{int(6*timeRatio),int(21)},{255,0,0,alpha}); //Right
}
if(p2.idleTime>=120.f&&p2.isActive){
//Over the next 40 seconds, the outline of the pad will slowly enclose in.
const float timeRatio{std::min(1.f-((160.f-p2.idleTime)/40.f),1.f)};
const uint8_t alpha{uint8_t(p2.flashRed?255:uint8_t(timeRatio*48))};
FillRect({12,0},{int(11),int(11*timeRatio)},{255,0,0,uint8_t(alpha)}); //Top
FillRect({12,int(21-11*timeRatio+1)},{int(11),int(11*timeRatio)},{255,0,0,uint8_t(alpha)}); //Bottom
FillRect({12,0},{int(6*timeRatio),int(21)},{255,0,0,alpha}); //Left
FillRect({12+int(12-6*timeRatio+1),0},{int(6*timeRatio),int(21)},{255,0,0,uint8_t(alpha)}); //Right
}
if(p1.idleTime>=600.f)p1.isActive=false;
if(p2.idleTime>=600.f)p2.isActive=false;
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.lastNoteHit=0.f;
p1.consecutiveNotesHit=std::clamp(p1.consecutiveNotesHit-10,0,100);
}
if(p2.lastNoteHit>=10.f){
p2.lastNoteHit=0.f;
p2.consecutiveNotesHit=std::clamp(p2.consecutiveNotesHit-10,0,100);
}
if(p1.consecutiveNotesHit>=100){
p1.idleTime=0.f;
p1.isActive=true;
p1.alertActive=false;
}
if(p2.consecutiveNotesHit>=100){
p2.idleTime=0.f;
p2.isActive=true;
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!!
}
if(p1.alertActive){
p1.flashTime-=fElapsedTime;
if(p1.flashTime<=0.f){
p1.flashRed=!p1.flashRed;
p1.flashTime=1.f;
}
}
if(p2.alertActive){
p2.flashTime-=fElapsedTime;
if(p2.flashTime<=0.f){
p2.flashRed=!p2.flashRed;
p2.flashTime=1.f;
}
}
}
#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);
@ -96,41 +163,6 @@ public:
DrawRect({12,7},{3,6},VERY_DARK_CYAN);
}
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);
return true;

Loading…
Cancel
Save