Commits

Radomir Dopieralski committed e5e4eb7

Add sleep_behavior

  • Participants
  • Parent commits 9bd3890

Comments (0)

Files changed (1)

File jelly/mobs.py

 }
 
 
+def sleep_behavior(mob, level):
+    if mob.status.get('asleep', True):
+        return True
+    return False
+
+
 def attack_behavior(mob, level):
     if dist(level.pc.pos, mob.pos) <= 1:
         level.attack(mob, pos2dir(mob.pos, level.pc.pos), level.pc)
+        mob.status['asleep'] = False
         return True
     return False
 
 
 
 def slow_behavior(mob, level):
-    mob.wait = not getattr(mob, 'wait', False)
-    if mob.wait:
+    mob.status['wait'] = not mob.status.get('wait', False)
+    if mob.status['wait']:
         return True
     return False
 
     def __init__(self, (x, y)):
         self.pos = x, y
         self.hp = self.max_hp
+        self.status = {}
 
     def make_sprite(self, tiles):
         sprite = self.Sprite(tiles, self.pos, self.animation)
 
     def hit(self, level, attacker):
         self.hp -= 1
+        self.status['asleep'] = False
         if self.hp <= 0:
             level.kill(self)
         return True
     name = 'purple jelly'
     color = 1
     animation = [46, 46, 47, 47, 47, 47]
-    behaviors = [attack_behavior, wander_behavior]
+    behaviors = [attack_behavior, sleep_behavior, wander_behavior]
 
 
 class RedJelly(Mob):