Allow pause with ESC

This commit is contained in:
Gabriel Augendre 2018-04-30 20:38:24 +02:00
parent 9ba1ceff72
commit cf534e1f13
No known key found for this signature in database
GPG key ID: F360212F958357D4

View file

@ -60,6 +60,14 @@ def main():
snake.direction = Direction.UP snake.direction = Direction.UP
elif event.key == pglocals.K_RIGHT or event.key == pglocals.K_d: elif event.key == pglocals.K_RIGHT or event.key == pglocals.K_d:
snake.direction = Direction.RIGHT 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) dirty_rects = snake.move(screen, apple)
if snake.dead: if snake.dead: