Skip to content

Commit

Permalink
fix: stopped snake movement when the game is inactive or menu is shown
Browse files Browse the repository at this point in the history
  • Loading branch information
zEuS0390 committed Jul 27, 2024
1 parent ffc77e6 commit e914ce5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/snakeGame.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
#include "windowGrid.hpp"
#include "snakeGame.hpp"
Expand Down Expand Up @@ -72,10 +71,12 @@ void snakeGame::events ()
window.close();
break;
case Event::LostFocus:
snakeObj.isMoving = false;
if (!interface.isMenu)
snakeObj.isMoving = false;
break;
case Event::GainedFocus:
snakeObj.isMoving = true;
if (!interface.isMenu)
snakeObj.isMoving = true;
break;
case Event::KeyPressed:
if (!is_keypressed)
Expand Down Expand Up @@ -150,6 +151,7 @@ void snakeGame::events ()
score = 0;
resetGame();
interface.isMenu = true;
snakeObj.isMoving = false;
}
}
}
Expand Down

0 comments on commit e914ce5

Please sign in to comment.