changeset 353:3ac03073218f

Don't allow tranformations if they'll get us stuck
author Neil Muller <drnlmuller@gmail.com>
date Sat, 09 Apr 2011 13:56:48 +0200
parents 4e158a7bd119
children b37dbc557ae0
files skaapsteker/sprites/player.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/sprites/player.py	Sat Apr 09 13:47:21 2011 +0200
+++ b/skaapsteker/sprites/player.py	Sat Apr 09 13:56:48 2011 +0200
@@ -68,12 +68,13 @@
         cand_collide_rect.midbottom = cur_pos
         # We always allow the attacking animation frames
         if not self.check_collide_rect(cand_collide_rect, cand_rect, cand_image) and not self.attacking:
-            return
+            return False
         self.image = cand_image
         self.collide_rect = cand_collide_rect
         self.rect = cand_rect
         self.rect_offset = cand_rect_offset
         self.init_pos()
+        return True
 
     def update(self):
         self._touching_actionables = []
@@ -225,12 +226,18 @@
         if self.shape == 'fox':
             # Become human
             if self.the_world.fox.has_fan:
-                self.the_world.fox.shape = 'human_with_fan'
+                self.shape = 'human_with_fan'
             else:
-                self.the_world.fox.shape = 'human'
+                self.shape = 'human'
         else:
-            self.the_world.fox.shape = 'fox'
-        self.shape = self.the_world.fox.shape
+            self.shape = 'fox'
+        # Check the transformation is feasible
+        if self.set_image():
+            # Transformation succeeded
+            self.the_world.fox.shape = self.shape
+        else:
+            # Back out of transformation
+            self.shape = self.the_world.fox.shape
 
     def action_right(self):
         if self.facing != 'right':