changeset 373:a2efe5470b79

start of patrolling monsters
author Neil Muller <drnlmuller@gmail.com>
date Sat, 09 Apr 2011 15:00:53 +0200
parents e1fb91717b07
children 9530b8dbda5f
files data/levels/town.json skaapsteker/sprites/base.py skaapsteker/sprites/enemies.py
diffstat 3 files changed, 36 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/data/levels/town.json	Sat Apr 09 14:47:27 2011 +0200
+++ b/data/levels/town.json	Sat Apr 09 15:00:53 2011 +0200
@@ -29,11 +29,11 @@
         "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
     ],
     "enemies": [                                                                              
-        {"type": "RedOni", "pos": [3, 8], "direction": "left" },    
-        {"type": "RedOni", "pos": [10, 11], "direction": "right" },
-        {"type": "RedOni", "pos": [23, 9], "direction": "left" },
-        {"type": "RedOni", "pos": [64, 6], "direction": "left" },                                 
-        {"type": "RedOni", "pos": [63, 14], "direction": "left" }
+        {"type": "PatrollingOni", "pos": [3, 8], "direction": "left" },    
+        {"type": "PatrollingOni", "pos": [10, 11], "direction": "right" },
+        {"type": "PatrollingOni", "pos": [23, 9], "direction": "left" },
+        {"type": "PatrollingOni", "pos": [64, 6], "direction": "left" },                                 
+        {"type": "PatrollingOni", "pos": [63, 14], "direction": "left" }
     ],
     "doorways": {
         "starting": {"type": "Doorway", "pos": [5, 15], "facing": "right", "leadsto": "road.to_town"},
@@ -42,4 +42,4 @@
         "to_market": {"type": "Doorway", "pos": [44, 6], "facing": "right", "leadsto": "market.starting"},
         "to_celestial_plane": {"type": "Doorway", "pos": [59, 14], "facing": "left", "leadsto": "celestial_plane.starting"}
     }
-}
\ No newline at end of file
+}
--- 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):
 
--- a/skaapsteker/sprites/enemies.py	Sat Apr 09 14:47:27 2011 +0200
+++ b/skaapsteker/sprites/enemies.py	Sat Apr 09 15:00:53 2011 +0200
@@ -1,4 +1,4 @@
-from base import Monster
+from base import Monster, PatrollingMonster
 from pygame import transform
 
 
@@ -31,3 +31,7 @@
 
 class FireballOni(RedOni):
     pass # TODO
+
+
+class PatrollingOni(RedOni, PatrollingMonster):
+    pass