From 2c65026e6444af76bf8ba6f03fd43ef45b74ea85 Mon Sep 17 00:00:00 2001 From: Daniel Francis Date: Mon, 07 Jan 2013 15:09:46 +0000 Subject: Fix use of pygame screen Signed-off-by: Daniel Francis --- diff --git a/game.py b/game.py index 8f24065..ca83ea2 100644 --- a/game.py +++ b/game.py @@ -100,20 +100,6 @@ class MazeGame: # keep a list of all players, local and remote, self.allplayers = [] + self.localplayers - self.screen = screen - canvas_size = screen.get_size() - self.aspectRatio = canvas_size[0] / float(canvas_size[1]) - - # start with a small maze using a seed that will be different - # each time you play - data = {'seed': int(time.time()), - 'width': int(9 * self.aspectRatio), - 'height': 9} - - log.debug('Starting the game with: %s', data) - self.maze = Maze(**data) - self.reset() - self.frame = 0 self.font = pygame.font.Font(None, 30) @@ -428,9 +414,88 @@ class MazeGame: return False def run(self): - self.screen = pygame.display.get_surface() - pygame.display.init() - + """Run the main loop of the game.""" + self.screen = pygame.display.get_surface() + canvas_size = self.screen.get_size() + self.aspectRatio = canvas_size[0] / float(canvas_size[1]) + + # start with a small maze using a seed that will be different + # each time you play + data = {'seed': int(time.time()), + 'width': int(9 * self.aspectRatio), + 'height': 9} + + log.debug('Starting the game with: %s', data) + self.maze = Maze(**data) + self.reset() + pygame.display.init() + # lets draw once before we enter the event loop + + clock = pygame.time.Clock() + pygame.display.flip() + + 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) + self.frame += 1 + # process all queued events + for event in pausescreen.get_events(sleep_timeout=30): + self.processEvent(event) + + self.animate() + self.draw() + + pygame.display.update() + # don't animate faster than about 20 frames per second + # this keeps the speed reasonable and limits cpu usage + clock.tick(25) """Run the main loop of the game.""" + # lets draw once before we enter the event loop + + clock = pygame.time.Clock() + pygame.display.flip() + + 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) + self.frame += 1 + # process all queued events + for event in pausescreen.get_events(sleep_timeout=30): + self.processEvent(event) + + self.animate() + self.draw() + + pygame.display.update() + # don't animate faster than about 20 frames per second + # this keeps the speed reasonable and limits cpu usage + clock.tick(25) """Run the main loop of the game.""" + # lets draw once before we enter the event loop + + clock = pygame.time.Clock() + pygame.display.flip() + + 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) + self.frame += 1 + # process all queued events + for event in pausescreen.get_events(sleep_timeout=30): + self.processEvent(event) + + self.animate() + self.draw() + + pygame.display.update() + # don't animate faster than about 20 frames per second + # this keeps the speed reasonable and limits cpu usage + clock.tick(25) + def harder(self): """Make a new maze that is harder than the current one.""" # both width and height must be odd -- cgit v0.9.1