SMX_PGE/sample/PGEX_SMX_Example.cpp

149 lines
5.3 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
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{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;
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;
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
}
2024-11-26 22:51:23 -06:00
#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);
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
}
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!!
}
2024-11-26 22:51:23 -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;
}