changeset 242:c30fcf903d29

Add update force parameter, so we can transition out of attacking animations even if it introduce a new collision
author Neil Muller <drnlmuller@gmail.com>
date Thu, 07 Apr 2011 15:01:23 +0200
parents 4c5941cf2b7f
children 4050e77dade6
files skaapsteker/sprites/base.py
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/sprites/base.py	Thu Apr 07 14:58:16 2011 +0200
+++ b/skaapsteker/sprites/base.py	Thu Apr 07 15:01:23 2011 +0200
@@ -80,7 +80,7 @@
         self._update_image()
         self.setup(**opts)
 
-    def _update_image(self):
+    def _update_image(self, force=False):
         if self.facing:
             images = self._animations[self._animation][self.facing]
         else:
@@ -97,7 +97,7 @@
         cand_rect.midbottom = cur_pos[0] + cand_rect_offset[0], cur_pos[1] + cand_rect_offset[1]
         cand_collide_rect.midbottom = cur_pos
 
-        if not self.check_collide_rect(cand_collide_rect, cand_rect, cand_image) and not self._animation == 'attacking':
+        if not self.check_collide_rect(cand_collide_rect, cand_rect, cand_image) and not force:
             return
 
         self.image = cand_image
@@ -110,7 +110,10 @@
         if self._tick > 10:
             self._tick = 0
             self._frame += 1
-            self._update_image()
+            force = False
+            if self._animation == 'attacking':
+                force = True
+            self._update_image(force)
         self._tick += 1
 
 
@@ -146,7 +149,7 @@
                 # We've just looped through the animation sequence
                 self._animation = self._old_state
                 self.facing = self._old_facing
-                self._update_image()
+                self._update_image(True)
             elif self._frame == self.attack_frame and self._tick == 5:
                 # Attack the player
                 self.do_attack()
@@ -166,7 +169,7 @@
             self._animation = 'attacking'
             self._tick = 1
             self._frame = 0  # Start the attack from the beginning
-            self._update_image()
+            self._update_image(True)
         else:
             player.damage(1)  # collision damage