From 41bebb262aa8f346ce6cdaefd854c9077ae84f97 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sun, 17 Dec 2017 19:18:23 +0000 Subject: Implement pausing. --- src/common.hpp | 3 ++- src/game/game.cpp | 5 ++++- src/game/game.hpp | 2 ++ src/game/interface.cpp | 9 +++++++++ src/game/text.cpp | 12 ++++++++++++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/common.hpp b/src/common.hpp index f269370..4b20ced 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -219,7 +219,8 @@ namespace game { public: world::world_t world; interface::state_t *interface; - double now, dt; + double now = 0.0, dt; + bool paused = false; procgen::prng_t dice_prng; void start(void); diff --git a/src/game/game.cpp b/src/game/game.cpp index fb130d9..e5f32f5 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -131,8 +131,11 @@ void state_t::tick(double now_, double dt_) uint32_t i; } u; - now = now_; + if (paused) + return; + dt = dt_; + now += dt; // FIXME: Is this non-deterministic enough? u.d = now; diff --git a/src/game/game.hpp b/src/game/game.hpp index d055aa5..0bc2da2 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -71,6 +71,8 @@ namespace game { extern language_t language; typedef enum { + PAUSED, + UNPAUSED, SAY_NO_PATH, SAY_BLOCKED, SAY_READY, diff --git a/src/game/interface.cpp b/src/game/interface.cpp index f574732..f4403ea 100644 --- a/src/game/interface.cpp +++ b/src/game/interface.cpp @@ -3,6 +3,8 @@ namespace interface { +using namespace game; // FIXME + state_t::state_t(sf::RenderWindow *window_, game::state_t *game_) { window = window_; @@ -101,6 +103,13 @@ void state_t::tick(double dt) case sf::Event::KeyPressed: switch (event.key.code) { + case sf::Keyboard::Key::Space: + game->paused ^= 1; + if (game->paused) + print(text::get(text::PAUSED)); + else + print(text::get(text::UNPAUSED)); + break; case sf::Keyboard::Key::F1: debug_draw_cmodels ^= 1; print("debug_draw_cmodels = " + std::to_string(debug_draw_cmodels)); diff --git a/src/game/text.cpp b/src/game/text.cpp index bdd68ed..00441f8 100644 --- a/src/game/text.cpp +++ b/src/game/text.cpp @@ -11,6 +11,12 @@ static const char *soldier_names[] = { static std::string get_english(index_t index) { switch (index) { + case PAUSED: + return "PAUSED"; + + case UNPAUSED: + return "UNPAUSED"; + case SAY_BLOCKED: return "Something is in my way."; @@ -58,6 +64,12 @@ static std::string get_english(index_t index) static std::string get_polish(index_t index) { switch (index) { + case PAUSED: + return "WSTRZYMANO"; + + case UNPAUSED: + return "WZNOWIONO"; + case SAY_BLOCKED: return "Coś jest na mojej drodze."; -- cgit