Browse Source

fixup! implement pause state

master
noerw 1 year ago
parent
commit
2fdaf22ed3
2 changed files with 10 additions and 4 deletions
  1. 8
    2
      game.cpp
  2. 2
    2
      main.cpp

+ 8
- 2
game.cpp View File

@@ -97,8 +97,14 @@ namespace Proto4 {
97 97
     }
98 98
 
99 99
     // TODO: pause menu
100
-    void Game::pause() { state = GameState::Paused; }
101
-    void Game::resume() { state = GameState::Running; }
100
+    void Game::pause() {
101
+        if (state == GameState::Running)
102
+            state = GameState::Paused;
103
+    }
104
+    void Game::resume() {
105
+        if (state == GameState::Paused)
106
+            state = GameState::Running;
107
+    }
102 108
 
103 109
     void Game::resize(sf::Event &resizeEvent) {
104 110
         mainView.setSize(resizeEvent.size.width, resizeEvent.size.height);

+ 2
- 2
main.cpp View File

@@ -92,11 +92,11 @@ namespace Proto4 {
92 92
         while (window.pollEvent(event)) {
93 93
             switch (event.type) {
94 94
             case sf::Event::LostFocus:
95
-                if (state == AppState::Game) game.pause();
95
+                game.pause();
96 96
                 break;
97 97
 
98 98
             case sf::Event::GainedFocus:
99
-                if (state == AppState::Game) game.resume();
99
+                game.resume();
100 100
                 break;
101 101
 
102 102
             case sf::Event::Resized:

Loading…
Cancel
Save