changeset 9:48c784b63eaf

Further tweak autorotation
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sun, 11 Mar 2012 21:49:05 +0100
parents add2b6c52187
children a822c9f688f2
files jelly/level.py jelly/mobs.py
diffstat 2 files changed, 9 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/jelly/level.py	Sun Mar 11 21:41:56 2012 +0100
+++ b/jelly/level.py	Sun Mar 11 21:49:05 2012 +0100
@@ -83,13 +83,6 @@
     def attack(self, mob, direction, other):
         self.events.append(('mob_attack', mob, direction, other))
         self.events.append(('mob_dust', mob, 4, -2))
-        if other is None:
-            x, y = mob.pos
-            for other in self.mobs:
-                if other.pos == (x + DX[direction], y + DY[direction]):
-                    break
-            else:
-                other = None
         if other is not None:
             self.hit(other, mob)
 
--- a/jelly/mobs.py	Sun Mar 11 21:41:56 2012 +0100
+++ b/jelly/mobs.py	Sun Mar 11 21:49:05 2012 +0100
@@ -160,12 +160,15 @@
             else:
                 other = None
             if other is None:
-                if len(level.mobs) > 1:
-                    other = min((m for m in level.mobs if m != self),
-                        key=lambda m: dist(self.pos, m.pos))
-                    self.direction = pos2dir(self.pos, other.pos)
-            if other is not None and not keys[pg.K_LCTRL]:
-                level.attack(self, self.direction, None)
+                for m in level.mobs:
+                    if m == self:
+                        continue
+                    if dist(self.pos, m.pos) <= 1:
+                        other = m
+                        self.direction = pos2dir(self.pos, other.pos)
+                        break
+            if not keys[pg.K_LCTRL]:
+                level.attack(self, self.direction, other)
                 return True
         elif not keys[pg.K_LSHIFT]:
             for key, direction in KEY_DIRS.iteritems():