changeset 42:8d0054b3240a

Add waiting
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sat, 10 Mar 2012 13:48:57 +0100
parents 6b1e309eafc3
children 2a1d0ace5ecc
files mhrok/display.py mhrok/level.py mhrok/mobs.py mhrok/sprites.py
diffstat 4 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mhrok/display.py	Sat Mar 10 13:22:09 2012 +0100
+++ b/mhrok/display.py	Sat Mar 10 13:48:57 2012 +0100
@@ -90,6 +90,9 @@
     def on_mob_stand(self, mob, direction):
         mob.sprite.set_animation(mob.sprite.stand_animation(direction))
 
+    def on_mob_wait(self, mob, direction):
+        mob.sprite.set_animation(mob.sprite.wait_animation(direction))
+
 
 def load_tiles(filename, width, height):
     f = StringIO.StringIO(pkgutil.get_data('mhrok', filename))
--- a/mhrok/level.py	Sat Mar 10 13:22:09 2012 +0100
+++ b/mhrok/level.py	Sat Mar 10 13:48:57 2012 +0100
@@ -59,9 +59,13 @@
     def stand(self, mob, direction):
         if direction is None:
             return
-        mob.direction = direction
         self.events.append(('mob_stand', mob, direction))
 
+    def wait(self, mob, direction):
+        if direction is None:
+            return
+        self.events.append(('mob_wait', mob, direction))
+
     def is_blocked(self, pos):
         for m in self.mobs:
             if m.pos == pos:
--- a/mhrok/mobs.py	Sat Mar 10 13:22:09 2012 +0100
+++ b/mhrok/mobs.py	Sat Mar 10 13:48:57 2012 +0100
@@ -15,6 +15,7 @@
     pg.K_LEFT: 0,
     pg.K_DOWN: 3,
     pg.K_RIGHT: 2,
+    pg.K_SPACE: 4,
 }
 
 
@@ -95,7 +96,9 @@
                 break
         else:
             direction = None
-        if direction is not None:
+        if direction == 4:
+            level.wait(self, self.direction)
+        elif direction is not None:
             self.direction = direction
             try:
                 level.walk(self, direction)
--- a/mhrok/sprites.py	Sat Mar 10 13:22:09 2012 +0100
+++ b/mhrok/sprites.py	Sat Mar 10 13:48:57 2012 +0100
@@ -82,6 +82,12 @@
         frame = [5, 10, 15, 0][direction]
         self.image = self.frames[frame]
 
+    def wait_animation(self, direction):
+        for step in xrange(4):
+            yield None
+            frame = [5, 10, 15, 0][direction]
+            self.image = self.frames[frame]
+
 
 class Shadow(pygame.sprite.Sprite):
     def __init__(self, frames, owner):