From b8f62555e2911c964bdac9b438b71c070e21f1f1 Mon Sep 17 00:00:00 2001 From: Spejik Date: Tue, 23 Aug 2022 16:01:49 +0200 Subject: [PATCH] Fix restarting without modifying anything --- "toustova\304\215.cpp" | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git "a/toustova\304\215.cpp" "b/toustova\304\215.cpp" index 1e12bdf..253c356 100644 --- "a/toustova\304\215.cpp" +++ "b/toustova\304\215.cpp" @@ -6,6 +6,7 @@ static float sxm = 1.4; static float sym = 1.4; static float fs = false; +static bool loop = true; // Override base class with your custom functionality class Bramborak : public olc::PixelGameEngine @@ -39,15 +40,15 @@ class Bramborak : public olc::PixelGameEngine if ((canUpdate += elapsedTime) < 0.1) if (elapsedTime < mindelta) { mindelta -= 0.00001f; g = (g + 25) % 256; } else if (elapsedTime > maxdelta) { maxdelta += 0.00001f; r = (r + 25) % 256; } - else if (elapsedTime > mindelta && elapsedTime < maxdelta) { mindelta *= 50.0f; maxdelta /= 50.0f; b = (b + 25) % 256; } + else if (elapsedTime > mindelta && elapsedTime < maxdelta) { mindelta *= 69.0f; maxdelta /= 69.0f; b = (b + 25) % 256; } else { r = (r + 5) % 256; g = (g + 5) % 256; b = (b + 5) % 256; } - else if ((canUpdate += elapsedTime) > 0.5f) + else if ((canUpdate += elapsedTime) > 0.2f) { canUpdate = 0.0f; mindelta = maxdelta = elapsedTime; } - if (std::fmod(canUpdate, 0.1) < 0.05) + if (std::fmod(canUpdate, 0.05) < 0.02) { if (r0 > r) r0 -= 1; else if (r0 < r)r0 += 1; @@ -68,29 +69,29 @@ class Bramborak : public olc::PixelGameEngine if (GetKey(olc::F).bReleased) { fs = !fs; + loop = true; olc_Terminate(); - return true; } } if (hx = GetKey(olc::X).bHeld) { - DrawString({ 20, 40 }, "Modifiyng: X", olc::Pixel(256 - r0, 256 - g0, 256 - b0), 2); + DrawString({ 20, 40 }, "Modifying: X", olc::Pixel(256 - r0, 256 - g0, 256 - b0), 2); } if (hy = GetKey(olc::Y).bHeld) { - DrawString({ 20, 60 }, "Modifiyng: Y", olc::Pixel(256 - r0, 256 - g0, 256 - b0), 2); + DrawString({ 20, 60 }, "Modifying: Y", olc::Pixel(256 - r0, 256 - g0, 256 - b0), 2); } if (GetKey(olc::NP_ADD).bReleased) { - if (hx) sxm = std::clamp(sxm += 0.2, 0.1f, 5.0f); - if (hy) sym = std::clamp(sym += 0.2, 0.1f, 5.0f); - olc_Terminate(); + if (hx) sxm = std::clamp(sxm += 0.2, 0.2f, 6.0f); + if (hy) sym = std::clamp(sym += 0.2, 0.2f, 6.0f); + if (hx || hy) { loop = true; olc_Terminate(); } } else if (GetKey(olc::NP_SUB).bReleased) { - if (hx) sxm = std::clamp(sxm -= 0.2, 0.1f, 5.0f); - if (hy) sym = std::clamp(sym -= 0.2, 0.1f, 5.0f); - olc_Terminate(); + if (hx) sxm = std::clamp(sxm -= 0.2, 0.2f, 6.0f); + if (hy) sym = std::clamp(sym -= 0.2, 0.2f, 6.0f); + if (hx || hy) { loop = true; olc_Terminate(); } } return true; @@ -100,12 +101,14 @@ class Bramborak : public olc::PixelGameEngine int main() { a_terrible_loop: - auto a = 1920.0f * sxm; - auto b = 1080.0f * sym; + loop = !loop; + int32_t a = 1920 * sxm; + int32_t b = 1080 * sym; Bramborak tortila(a, b); - std::cout << a << 'x' << b << std::endl; + std::cout << std::format("{}x{}:{}", a, b, fs) << std::endl; if (tortila.Construct(a, b, 1, 1, fs)) - if (tortila.Start() == olc::rcode::OK) - goto a_terrible_loop; + tortila.Start(); + if (loop) + goto a_terrible_loop; return 0; } \ No newline at end of file