changeset 389:48e39d1ad5ae

Add pause button (mostly for creating screenshots).
author Simon Cross <hodgestar@gmail.com>
date Sat, 17 Sep 2011 01:24:19 +0200
parents 88d9509fd2c2
children 38572d326af9
files mamba/widgets/game.py mamba/world.py
diffstat 2 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/widgets/game.py	Sat Sep 17 01:47:35 2011 +0200
+++ b/mamba/widgets/game.py	Sat Sep 17 01:24:19 2011 +0200
@@ -1,7 +1,7 @@
 """Display the game area."""
 
 from pygame.rect import Rect
-from pygame.locals import KEYDOWN, K_LEFT, K_RIGHT, K_DOWN, K_UP
+from pygame.locals import KEYDOWN, K_LEFT, K_RIGHT, K_DOWN, K_UP, K_p
 
 from mamba.constants import UP, DOWN, LEFT, RIGHT
 from mamba.widgets.base import Widget
@@ -26,6 +26,7 @@
         actions[K_RIGHT] = (self.world.snake.send_new_direction, (RIGHT,))
         actions[K_DOWN] = (self.world.snake.send_new_direction, (DOWN,))
         actions[K_UP] = (self.world.snake.send_new_direction, (UP,))
+        actions[K_p] = (self.world.toggle_pause, ())
         return actions
 
     def action_callback(self, ev, widget):
--- a/mamba/world.py	Sat Sep 17 01:47:35 2011 +0200
+++ b/mamba/world.py	Sat Sep 17 01:24:19 2011 +0200
@@ -47,6 +47,12 @@
         was_paused, self._paused = self._paused, False
         return was_paused == True
 
+    def toggle_pause(self):
+        if self._paused:
+            self.resume()
+        else:
+            self.pause()
+
     def restart(self):
         stop_sound()
         self.level.restart()