diff skaapsteker/sprites/base.py @ 373:a2efe5470b79

start of patrolling monsters
author Neil Muller <drnlmuller@gmail.com>
date Sat, 09 Apr 2011 15:00:53 +0200
parents 92cf515a6cf6
children 9530b8dbda5f
line wrap: on
line diff
--- a/skaapsteker/sprites/base.py	Sat Apr 09 14:47:27 2011 +0200
+++ b/skaapsteker/sprites/base.py	Sat Apr 09 15:00:53 2011 +0200
@@ -158,7 +158,6 @@
         self._done_attack = False
         self.setup(**opts)
 
-
     def collided_player(self, player):
         print "%s collided with player" % self
         self.start_attack(player)
@@ -203,6 +202,31 @@
         if self.health < 0:
             self.kill()
 
+class PatrollingMonster(Monster):
+    """Monster that collides with horizontal geography"""
+
+    debug_color = (120, 240, 120)
+
+    patrol_speed = (200, 0)
+
+    def update(self):
+        Monster.update(self)
+        if self._animation == 'running':
+            if self.facing == 'left':
+                self.velocity = (-self.patrol_speed[0], 0)
+            elif self.facing == 'right':
+                self.velocity = self.patrol_speed
+
+    def collided(self, other):
+        Monster.collided(self, other)
+        # Check if the object we've collided with is the same height our higher than us
+        if other.block and other.collide_rect.bottom <= self.collide_rect.bottom:
+            # Change direction
+            if self.facing == 'left':
+                self.facing = 'right'
+            else:
+                self.facing = 'left'
+
 
 class NPC(AnimatedGameSprite):