changeset 44:e551390b0a1b

monsters block monsters now
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sat, 10 Sep 2011 11:56:53 +0200
parents 74ea37d90add
children 4898a1f23806
files qq.py
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/qq.py	Sat Sep 10 11:51:03 2011 +0200
+++ b/qq.py	Sat Sep 10 11:56:53 2011 +0200
@@ -159,13 +159,23 @@
         self.direction = 2
         self.target = target
 
-    def go(self, level, direction):
+    def move(self, dx, dy):
+        """Change the position of the sprite on screen."""
+
+        self.rect.move_ip(dx, dy)
+        self.depth = self.rect.midbottom[1] + 1
+
+    def go(self, level, direction, monsters):
         x, y = self.pos
         self.direction = direction
         dx, dy = DX[self.direction], DY[self.direction]
-        if level.is_blocking(x + dx, y + dy):
+        pos = x + dx, y + dy
+        if level.is_blocking(*pos):
             return False
-        self.pos = x + dx, y + dy
+        for monster in monsters:
+            if monster.pos == pos:
+                return False
+        self.pos = pos
         for frame in self.animation:
             pass
         self.animation = self.walk_animation()
@@ -386,7 +396,7 @@
                 return
             for monster in self.monsters:
                 if monster.pos == pos:
-                    if not monster.go(self.level, d):
+                    if not monster.go(self.level, d, self.monsters):
                         return
             self.player.animation = self.player.walk_animation()
             self.player.pos = pos