From cf534e1f136a6ad7e22f2c5323e6f792aa3b2895 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 30 Apr 2018 20:38:24 +0200 Subject: [PATCH] Allow pause with ESC --- main.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.py b/main.py index 6db0c09..7f9e1aa 100644 --- a/main.py +++ b/main.py @@ -60,6 +60,14 @@ def main(): snake.direction = Direction.UP elif event.key == pglocals.K_RIGHT or event.key == pglocals.K_d: snake.direction = Direction.RIGHT + elif event.key == pglocals.K_ESCAPE: + pause = True + while pause: + clock.tick(5) + for event in pygame.event.get(): + if event.type == pglocals.KEYDOWN and event.key == pglocals.K_ESCAPE: + pause = False + break dirty_rects = snake.move(screen, apple) if snake.dead: