# HG changeset patch # User Simon Cross # Date 1316215459 -7200 # Node ID 48e39d1ad5ae2d6632176cf5ec512a4340331460 # Parent 88d9509fd2c2a20435ce4f737325a5f97903f9de Add pause button (mostly for creating screenshots). diff -r 88d9509fd2c2 -r 48e39d1ad5ae mamba/widgets/game.py --- 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): diff -r 88d9509fd2c2 -r 48e39d1ad5ae mamba/world.py --- 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()