diff options
author | Daniel Francis <francis@sugarlabs.org> | 2013-01-07 15:09:46 (GMT) |
---|---|---|
committer | Daniel Francis <francis@sugarlabs.org> | 2013-01-07 15:09:46 (GMT) |
commit | 2c65026e6444af76bf8ba6f03fd43ef45b74ea85 (patch) | |
tree | 9740dd7e8a3bb0d5136e235b3a2b1cecad30f58e | |
parent | baa53ad8cb0e51f408dc167c41e9eb7f922d4272 (diff) |
Fix use of pygame screen
Signed-off-by: Daniel Francis <francis@sugarlabs.org>
-rw-r--r-- | game.py | 99 |
1 files changed, 82 insertions, 17 deletions
@@ -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 |