diff --git a/README.md b/README.md index 5807b57..748f4c4 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Play it at https://replit.com/@UniqueOstrich18/CLI-Snake ### Controls: - WASD to control the snake + - P to pause/resume - X to quit game - Arrow keys to navigate in menus - C on title screen to access settings diff --git a/extradata.json b/extradata.json index f16aecb..692b4ef 100644 --- a/extradata.json +++ b/extradata.json @@ -111,6 +111,7 @@ "save": false, "default": [" - WASD to move snake", + " - P to pause/resume", " - X to quit game", "", "Tip: You can make the snake move faster by moving it", diff --git a/snake.py b/snake.py index 646c52b..b9bff17 100644 --- a/snake.py +++ b/snake.py @@ -65,6 +65,7 @@ def resetGame(self): self.extra_turn = False self.extra_turn_active = False self.inputQueue = [] + self.paused = False self.currentHighScore = 0 self.playSound = False self.foodCount = 1 @@ -659,6 +660,10 @@ def getInput(self): self.resetTimer = True break + #toggle pause if key p is pressed + elif keyString == "p": + self.paused = not self.paused + #sleep for a bit so we don't waste cpu time.sleep(0.01) @@ -706,6 +711,9 @@ def main(self): if self.stop == True: break + if self.paused: + continue + if len(self.inputQueue) > 0: self.direction = self.inputQueue.pop(0)