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.
SMX_PGE/sample/PGEX_SMX_Example.cpp

181 lines
6.8 KiB

#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#include "PGEX_SMX.h"
#include "util.h"
using namespace olc;
class SMX_PGE : public olc::PixelGameEngine
{
PGEX_SMX smx;
2 years ago
bool paused = false;
int mode = 0;
vf2d playerPos = { 0,0 };
bool enabled{true};
public:
SMX_PGE()
{
sAppName = "SMX PGE";
}
public:
bool OnUserCreate() override
{
// Called once at the start, so create things here
//smx.EnableLogMessages(true);
return true;
}
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{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;
bool OnUserUpdate(float fElapsedTime) override
{
Clear({0,0,0});
SetPixelMode(Pixel::ALPHA);
p1.lastNoteHit+=fElapsedTime;
p2.lastNoteHit+=fElapsedTime;
FillRect({0,0},{12,21},{32,0,32,64});
FillRect({12,0},{12,21},{0,32,32,64});
#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;
}
}
}
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(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(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(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(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(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(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(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);
}
SetPixelMode(Pixel::MASK);
return true;
}
};
int main()
{
SMX_PGE demo;
if (demo.Construct(24, 21, 50, 50,false,true))
demo.Start();
return 0;
}