changeset 409:ed26bbfec03a

Add up-down 'Fying' Oni
author Neil Muller <drnlmuller@gmail.com>
date Sat, 09 Apr 2011 17:26:25 +0200
parents bbfc2cc07ba4
children 115e738e209c
files data/levels/celestial_plane.json skaapsteker/sprites/base.py skaapsteker/sprites/enemies.py
diffstat 3 files changed, 60 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/data/levels/celestial_plane.json	Sat Apr 09 17:23:07 2011 +0200
+++ b/data/levels/celestial_plane.json	Sat Apr 09 17:26:25 2011 +0200
@@ -37,15 +37,15 @@
         "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
     ],
     "enemies": [
-        {"type": "RedOni", "pos": [26, 7], "direction": "left" },
-        {"type": "RedOni", "pos": [13, 10], "direction": "right" },
-        {"type": "RedOni", "pos": [18, 10], "direction": "left" },
-        {"type": "RedOni", "pos": [18, 24], "direction": "right" },
-        {"type": "RedOni", "pos": [12, 28], "direction": "left" },
-        {"type": "RedOni", "pos": [18, 28], "direction": "right" },
-        {"type": "RedOni", "pos": [24, 28], "direction": "left" }
+        {"type": "FlyingOni", "pos": [26, 7], "direction": "left" },
+        {"type": "FlyingOni", "pos": [13, 10], "direction": "right" },
+        {"type": "FlyingOni", "pos": [18, 10], "direction": "left" },
+        {"type": "FlyingOni", "pos": [18, 24], "direction": "right" },
+        {"type": "FlyingOni", "pos": [12, 28], "direction": "left" },
+        {"type": "FlyingOni", "pos": [18, 28], "direction": "right" },
+        {"type": "FlyingOni", "pos": [24, 28], "direction": "left" }
     ],
     "doorways": {
         "starting": {"type": "Doorway", "pos": [16, 4], "facing": "right", "leadsto": "town.to_celestial_plane"}
     }
-}
\ No newline at end of file
+}
--- a/skaapsteker/sprites/base.py	Sat Apr 09 17:23:07 2011 +0200
+++ b/skaapsteker/sprites/base.py	Sat Apr 09 17:26:25 2011 +0200
@@ -231,12 +231,15 @@
         # Check if the object we've collided with is the same height our higher than us
         if (other.block or other.floor) and other.collide_rect.bottom <= self.collide_rect.bottom:
             # Change direction
-            if self.facing == 'left':
-                self.facing = 'right'
-                self._update_image(True)
-            else:
-                self.facing = 'left'
-                self._update_image(True)
+            self.change_facing()
+
+    def change_facing(self):
+        if self.facing == 'left':
+            self.facing = 'right'
+            self._update_image(True)
+        else:
+            self.facing = 'left'
+            self._update_image(True)
 
     def check_floors(self, floors):
         """If we're only on 1 floor tile, and our centre is beyond half way,
@@ -248,12 +251,10 @@
 
         if self.facing == 'left':
             if self.collide_rect.centerx < floor.collide_rect.centerx:
-                self.facing = 'right'
-                self._update_image(True)
+                self.change_facing()
         else:
             if self.collide_rect.centerx > floor.collide_rect.centerx:
-                self.facing = 'left'
-                self._update_image(True)
+                self.change_facing()
 
 class NPC(AnimatedGameSprite):
 
--- a/skaapsteker/sprites/enemies.py	Sat Apr 09 17:23:07 2011 +0200
+++ b/skaapsteker/sprites/enemies.py	Sat Apr 09 17:26:25 2011 +0200
@@ -35,3 +35,44 @@
 
 class PatrollingOni(RedOni, PatrollingMonster):
     pass
+
+class FlyingOni(PatrollingOni):
+
+
+    gravitates = False
+
+    patrol_velocity = (0, 200)
+
+    def setup(self, direction):
+        PatrollingOni.setup(self, direction)
+        self.heading = 'up'
+
+    def update(self):
+        PatrollingOni.update(self)
+        if self._animation == 'running':
+            if self.heading == 'up':
+                self.velocity = (0, -self.patrol_velocity[1])
+            else:
+                self.velocity = (0, self.patrol_velocity[1])
+
+    def check_floors(self, floors):
+        pass
+
+    def collided(self, other):
+        if not other.block or not other.floor:
+            return
+        if other.collide_rect.bottom < self.collide_rect.bottom:
+            # We're colliding with something above us
+            if self.heading == 'up':
+                self.change_facing()
+        else:
+            if self.heading == 'down':
+                self.change_facing()
+
+    def change_facing(self):
+        if self.heading == 'up':
+            self.heading = 'down'
+        else:
+            self.heading = 'up'
+
+