|
|
|
@ -12,56 +12,32 @@ class SMX_PGE : public olc::PixelGameEngine |
|
|
|
|
public: |
|
|
|
|
SMX_PGE() |
|
|
|
|
{ |
|
|
|
|
sAppName = "SMX PGE"; |
|
|
|
|
sAppName = "SMX PGE - Bad Apple"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::vector<Renderable>video; |
|
|
|
|
int currentFrame{0}; |
|
|
|
|
double elapsedTime{0.f}; |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
bool OnUserCreate() override |
|
|
|
|
{ |
|
|
|
|
// Called once at the start, so create things here
|
|
|
|
|
const std::string badAppleVideoDir{"badapple"}; |
|
|
|
|
for(int frame=1;frame<=6572;frame++){ |
|
|
|
|
video.emplace_back(); |
|
|
|
|
video[frame-1].Load(std::format("{}/frame{}.png",badAppleVideoDir,frame)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
|
{ |
|
|
|
|
smx.GetPanel(RIGHT, 0).bHeld; |
|
|
|
|
if (GetKey(RIGHT).bPressed) { |
|
|
|
|
mode = (mode + 1) % 3; |
|
|
|
|
} |
|
|
|
|
switch (mode) { |
|
|
|
|
case 0: { |
|
|
|
|
if (GetKey(SPACE).bPressed) { |
|
|
|
|
paused = !paused; |
|
|
|
|
} |
|
|
|
|
// called once per frame
|
|
|
|
|
if (!paused) { |
|
|
|
|
for (int x = 0; x < ScreenWidth(); x++) |
|
|
|
|
for (int y = 0; y < ScreenHeight(); y++) |
|
|
|
|
Draw(x, y, olc::Pixel(rand() % 255, rand() % 255, rand() % 255)); |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case 1: { |
|
|
|
|
Clear(DARK_CYAN); |
|
|
|
|
DrawRect({ 1,1 }, { 9,18 }, RED); |
|
|
|
|
}break; |
|
|
|
|
case 2: { |
|
|
|
|
Clear(VERY_DARK_BLUE); |
|
|
|
|
FillCircle(playerPos, 3,VERY_DARK_GREY); |
|
|
|
|
DrawCircle(playerPos, 3); |
|
|
|
|
if (GetKey(W).bHeld) { |
|
|
|
|
playerPos.y -= 5*fElapsedTime; |
|
|
|
|
} |
|
|
|
|
if (GetKey(A).bHeld) { |
|
|
|
|
playerPos.x -= 5 * fElapsedTime; |
|
|
|
|
} |
|
|
|
|
if (GetKey(S).bHeld) { |
|
|
|
|
playerPos.y += 5 * fElapsedTime; |
|
|
|
|
} |
|
|
|
|
if (GetKey(D).bHeld) { |
|
|
|
|
playerPos.x += 5 * fElapsedTime; |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
Clear(BLACK); |
|
|
|
|
elapsedTime+=fElapsedTime; |
|
|
|
|
const int frame{int(std::clamp((elapsedTime-5)/(1/30.f),1.,6573.))}; |
|
|
|
|
DrawSprite({},video[frame-1].Sprite()); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
@ -70,7 +46,7 @@ public: |
|
|
|
|
int main() |
|
|
|
|
{ |
|
|
|
|
SMX_PGE demo; |
|
|
|
|
if (demo.Construct(12, 21, 50, 50)) |
|
|
|
|
if (demo.Construct(24, 21, 50, 50,false,true)) |
|
|
|
|
demo.Start(); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|