diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2013-06-17 20:38:30 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2013-06-17 20:55:02 (GMT) |
commit | b77aabde557b16e7f0e4f47608c0f7099316f3fd (patch) | |
tree | 1853ad14de3548710e784b32d9a98144ebed883a | |
parent | 531a572b9fcf201c2f30e889352a09742fded9be (diff) |
Redraw the maze when the screen is rotated
Signed-off-by: Walter Bender <walter@sugarlabs.org>
-rw-r--r-- | game.py | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -29,6 +29,8 @@ try: import json except ImportError: import simplejson as json +import gtk + import pygame import olpcgames @@ -41,6 +43,7 @@ import olpcgames.pausescreen as pausescreen import olpcgames.mesh as mesh from olpcgames.util import get_bundle_path from sugar.presence import presenceservice +from sugar.graphics.style import GRID_CELL_SIZE bundlepath = get_bundle_path() presenceService = presenceservice.get_instance() @@ -135,6 +138,33 @@ class MazeGame: pygame.K_KP1: (2, pygame.K_RIGHT) } + gtk.gdk.screen_get_default().connect('size-changed', + self.__configure_cb) + + def __configure_cb(self, event): + ''' Screen size has changed ''' + width = gtk.gdk.screen_width() + height = gtk.gdk.screen_height() - GRID_CELL_SIZE + self.aspectRatio = width / float(height) + pygame.display.set_mode((width, height), pygame.RESIZABLE) + + seed = self.maze.seed + if width < height: + if self.maze.width < self.maze.height: + self.maze = Maze(self.maze.seed, self.maze.width, + self.maze.height) + else: + self.maze = Maze(self.maze.seed, self.maze.height, + self.maze.width) + else: + if self.maze.width > self.maze.height: + self.maze = Maze(self.maze.seed, self.maze.width, + self.maze.height) + else: + self.maze = Maze(self.maze.seed, self.maze.height, + self.maze.width) + self.reset() + def game_running_time(self, newelapsed=None): return int(time.time() - self.game_start_time) @@ -435,6 +465,7 @@ class MazeGame: while self.running: clock.tick(25) + a, b, c, d = pygame.cursors.load_xbm('my_cursor.xbm', 'my_cursor_mask.xbm') pygame.mouse.set_cursor(a, b, c, d) |