SMX_PGE/sample/PGEX_SMX_Example.cpp

181 lines
6.8 KiB
C++
Raw Permalink 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 };
bool enabled{true};
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
2024-11-30 18:19:07 -06:00
//smx.EnableLogMessages(true);
2023-06-16 18:51:30 -05:00
return true;
}
2017-12-14 20:02:36 -06:00
2025-02-20 14:38:03 -06:00
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.
2025-02-20 14:38:03 -06:00
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};
};
2025-02-20 14:38:03 -06:00
Pad p1,p2;
2023-06-16 18:51:30 -05:00
bool OnUserUpdate(float fElapsedTime) override
{
2025-02-20 14:38:03 -06:00
Clear({0,0,0});
SetPixelMode(Pixel::ALPHA);
2025-02-20 14:38:03 -06:00
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;
}
}
}
2024-11-26 22:51:23 -06:00
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);
2025-02-20 14:38:03 -06:00
}
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);
2025-02-20 14:38:03 -06:00
}
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);
2025-02-20 14:38:03 -06:00
}
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);
2025-02-20 14:38:03 -06:00
}
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);
2025-02-20 14:38:03 -06:00
}
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);
2025-02-20 14:38:03 -06:00
}
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);
2025-02-20 14:38:03 -06:00
}
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);
2025-02-20 14:38:03 -06:00
}
SetPixelMode(Pixel::MASK);
2024-11-26 22:51:23 -06:00
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;
if (demo.Construct(24, 21, 50, 50,false,true))
2023-06-16 18:51:30 -05:00
demo.Start();
2017-12-14 20:02:36 -06:00
return 0;
}