Mercurial > rinkhals
comparison gamelib/engine.py @ 436:2b4cd86dfcaf
Better approximate constant framerate on move events, etc.
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 17:47:27 +0000 |
parents | 66bc99477155 |
children | e0b11d684ee8 |
comparison
equal
deleted
inserted
replaced
435:66bc99477155 | 436:2b4cd86dfcaf |
---|---|
246 elif e.type is KEYDOWN and e.key == K_ESCAPE: | 246 elif e.type is KEYDOWN and e.key == K_ESCAPE: |
247 self.dialog = check_exit() | 247 self.dialog = check_exit() |
248 elif e.type is MOVE_FOX_ID: | 248 elif e.type is MOVE_FOX_ID: |
249 # ensure no timers trigger while we're running | 249 # ensure no timers trigger while we're running |
250 pygame.time.set_timer(MOVE_FOX_ID, 0) | 250 pygame.time.set_timer(MOVE_FOX_ID, 0) |
251 cur_time = pygame.time.get_ticks() | |
251 # Clear any queued timer events, so we don't full the queue | 252 # Clear any queued timer events, so we don't full the queue |
252 pygame.event.clear(MOVE_FOX_ID) | 253 pygame.event.clear(MOVE_FOX_ID) |
253 # Ensure any outstanding animitions get cleaned up | 254 # Ensure any outstanding animitions get cleaned up |
254 self.cycle_count += 1 | 255 self.cycle_count += 1 |
255 if self.cycle_count > constants.NIGHT_LENGTH: | 256 if self.cycle_count > constants.NIGHT_LENGTH: |
256 return pygame.event.post(START_DAY) | 257 return pygame.event.post(START_DAY) |
257 if self.game.gameboard.do_night_step(): | 258 if self.game.gameboard.do_night_step(): |
258 # All foxes are gone/safe, so dawn happens | 259 # All foxes are gone/safe, so dawn happens |
259 return pygame.event.post(START_DAY) | 260 return pygame.event.post(START_DAY) |
260 # Re-enable timers | 261 # Re-enable timers |
261 pygame.time.set_timer(MOVE_FOX_ID, self.cycle_time) | 262 diff = pygame.time.get_ticks() - cur_time |
263 time_left = self.cycle_time - diff | |
264 if time_left < 0: | |
265 time_left = self.cycle_time | |
266 pygame.time.set_timer(MOVE_FOX_ID, time_left) | |
262 elif e.type is not QUIT: | 267 elif e.type is not QUIT: |
263 self.game.main_app.event(e) | 268 self.game.main_app.event(e) |
264 | 269 |
265 def loop(self): | 270 def loop(self): |
266 self.game.gameboard.loop() | 271 self.game.gameboard.loop() |