From f9fa21505107444c3126f67f5437dfd80042486c Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 30 Nov 2024 19:44:26 -0600 Subject: [PATCH] Bad apple video player. --- sample/PGEX_SMX_Example.cpp | 56 +++++++++++-------------------------- sample/SMXSample.vcxproj | 4 +-- 2 files changed, 18 insertions(+), 42 deletions(-) diff --git a/sample/PGEX_SMX_Example.cpp b/sample/PGEX_SMX_Example.cpp index 40b3b9f..b516fb4 100644 --- a/sample/PGEX_SMX_Example.cpp +++ b/sample/PGEX_SMX_Example.cpp @@ -12,56 +12,32 @@ class SMX_PGE : public olc::PixelGameEngine public: SMX_PGE() { - sAppName = "SMX PGE"; + sAppName = "SMX PGE - Bad Apple"; } + std::vectorvideo; + 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; diff --git a/sample/SMXSample.vcxproj b/sample/SMXSample.vcxproj index 967c204..c0ba713 100644 --- a/sample/SMXSample.vcxproj +++ b/sample/SMXSample.vcxproj @@ -62,7 +62,7 @@ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 4063;4100;4127;4201;4244;4275;4355;4505;4512;4702;4786;4996;4996;4005;4018;4389;4389;4800;4592;%(DisableSpecificWarnings) ..\sdk - stdcpp17 + stdcpp20 Console @@ -81,7 +81,7 @@ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 4063;4100;4127;4201;4244;4275;4355;4505;4512;4702;4786;4996;4996;4005;4018;4389;4389;4800;4592;%(DisableSpecificWarnings) ..\sdk - stdcpp17 + stdcpp20 Console