From 1a4780bad1cc40b43ebe6d93baba0f89572194d4 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan <tullivan99@gmail.com> Date: Fri, 20 Oct 2017 08:14:01 -0400 Subject: better pausing --- assets/style/winter/bg/bgFarMountain.png | Bin 28237 -> 28404 bytes include/gametime.hpp | 1 + main.cpp | 3 ++- src/gametime.cpp | 12 +++++++++--- xcf/snowmtns.xcf | Bin 421662 -> 423735 bytes 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/assets/style/winter/bg/bgFarMountain.png b/assets/style/winter/bg/bgFarMountain.png index 7db9b2e..3e3dee1 100644 Binary files a/assets/style/winter/bg/bgFarMountain.png and b/assets/style/winter/bg/bgFarMountain.png differ diff --git a/include/gametime.hpp b/include/gametime.hpp index 7999f1c..2433b28 100644 --- a/include/gametime.hpp +++ b/include/gametime.hpp @@ -9,6 +9,7 @@ namespace game { namespace time { void togglePause(void); void togglePause(bool state); + bool isPaused(void); /** * Sets the game's tick count to the desired amount. diff --git a/main.cpp b/main.cpp index c05a787..fad1315 100644 --- a/main.cpp +++ b/main.cpp @@ -137,7 +137,8 @@ int main(int argc, char *argv[]) for (auto& e : clone) game::events.emit<MainSDLEvent>(e); - game::engine.update(game::time::getDeltaTime()); + if (!game::time::isPaused()) + game::engine.update(game::time::getDeltaTime()); std::this_thread::sleep_for(1ms); }); diff --git a/src/gametime.cpp b/src/gametime.cpp index 6f6ac0e..7ef824c 100644 --- a/src/gametime.cpp +++ b/src/gametime.cpp @@ -17,6 +17,10 @@ namespace game { paused = state; } + bool isPaused(void) { + return paused; + } + void setTickCount(unsigned int t) { tickCount = t; } @@ -30,11 +34,13 @@ namespace game { } void tick(void) { - tickCount++; + if (!paused) + tickCount++; } void tick(unsigned int ticks) { - tickCount += ticks; + if (!paused) + tickCount += ticks; } void mainLoopHandler(void) { @@ -52,7 +58,7 @@ namespace game { static unsigned int accum = 0; accum += deltaTime; - if (accum > MSEC_PER_TICK) { + if (!paused && accum > MSEC_PER_TICK) { accum = 0.0f; return true; } diff --git a/xcf/snowmtns.xcf b/xcf/snowmtns.xcf index 663e714..4106d1e 100644 Binary files a/xcf/snowmtns.xcf and b/xcf/snowmtns.xcf differ -- cgit v1.2.3