changeset 233:d3d5352f5853

Twek speed loop. Document animation assumptions
author Neil Muller <drnlmuller@gmail.com>
date Sat, 05 Sep 2009 09:00:12 +0000
parents 0bd214cf9018
children ee1ac134022d
files gamelib/animations.py gamelib/engine.py
diffstat 2 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/animations.py	Fri Sep 04 23:59:52 2009 +0000
+++ b/gamelib/animations.py	Sat Sep 05 09:00:12 2009 +0000
@@ -13,6 +13,8 @@
        the sprites list.
        
        Ideally, animations should be quite short."""
+       # In the current implementation, sequences longer than 3 frames
+       # will cause issues as this will overrun the next move loop.
 
     def __init__(self, sequence, tile_pos):
         # Create the first frame
--- a/gamelib/engine.py	Fri Sep 04 23:59:52 2009 +0000
+++ b/gamelib/engine.py	Sat Sep 05 09:00:12 2009 +0000
@@ -152,9 +152,9 @@
         sound.play_sound("nightfall.ogg")
         # Add a timer to the event queue
         self.cycle_count = 0
-        self.cycle_time = 200
-        pygame.time.set_timer(MOVE_FOX_ID, self.cycle_time)
-        pygame.time.set_timer(ANIM_ID, 50)
+        self.cycle_time = SLOW_ANIM_SPEED
+        pygame.time.set_timer(MOVE_FOX_ID, 4*self.cycle_time)
+        pygame.time.set_timer(ANIM_ID, self.cycle_time)
         self.game.gameboard.spawn_foxes()
         sound.background_music("nighttime.ogg")
 
@@ -166,19 +166,21 @@
                 return GameOver(self.game)
             return DayState(self.game)
         elif e.type is KEYDOWN and e.key == K_d:
-            if self.cycle_time > 100:
-                self.cycle_time = 50  
-                pygame.time.set_timer(ANIM_ID, 25)
+            if self.cycle_time > FAST_ANIM_SPEED:
+                self.cycle_time = FAST_ANIM_SPEED
             else:
-                self.cycle_time = 200
-                pygame.time.set_timer(ANIM_ID, 50)
-            pygame.time.set_timer(MOVE_FOX_ID, self.cycle_time)
+                self.cycle_time = SLOW_ANIM_SPEED
+            pygame.time.set_timer(ANIM_ID, self.cycle_time)
+            pygame.time.set_timer(MOVE_FOX_ID, 4*self.cycle_time)
         elif e.type is KEYDOWN and e.key == K_ESCAPE:
             self.game.gameboard.set_cursor()
             return GameOver(self.game)
         elif e.type is ANIM_ID:
             self.game.gameboard.run_animations()
         elif e.type is MOVE_FOX_ID:
+            # Timer aren't nessecairly ordered, so we make sure
+            # we don't get a ANIM event until at least cycle after this
+            pygame.time.set_timer(ANIM_ID, self.cycle_time)
             self.cycle_count += 1
             if self.cycle_count > constants.NIGHT_LENGTH:
                 return pygame.event.post(START_DAY)
@@ -240,3 +242,8 @@
 ANIM_ID = USEREVENT + 6
 MOVE_FOXES = pygame.event.Event(MOVE_FOX_ID, name="MOVE_FOXES")
 QUIT = pygame.event.Event(QUIT)
+
+# Due to the way pgu's loop timing works, these will only get proceesed
+# at intervals of 10ms, so there's no point in them not being multiples of 10
+FAST_ANIM_SPEED=20
+SLOW_ANIM_SPEED=50