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 {
}

// TODO: pause menu
void Game::pause() { state = GameState::Paused; }
void Game::resume() { state = GameState::Running; }
void Game::pause() {
if (state == GameState::Running)
state = GameState::Paused;
}
void Game::resume() {
if (state == GameState::Paused)
state = GameState::Running;
}

void Game::resize(sf::Event &resizeEvent) {
mainView.setSize(resizeEvent.size.width, resizeEvent.size.height);

+ 2
- 2
main.cpp View File

@@ -92,11 +92,11 @@ namespace Proto4 {
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::LostFocus:
if (state == AppState::Game) game.pause();
game.pause();
break;

case sf::Event::GainedFocus:
if (state == AppState::Game) game.resume();
game.resume();
break;

case sf::Event::Resized:

Loading…
Cancel
Save