changeset 18:fa49938e730f

shoving the boulders around
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sun, 27 Apr 2014 15:25:49 +0200
parents b69ed0cdaee6
children 6e97c68e7ce8
files undermine/game.py undermine/sprites.py
diffstat 2 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/undermine/game.py	Sun Apr 27 14:49:31 2014 +0200
+++ b/undermine/game.py	Sun Apr 27 15:25:49 2014 +0200
@@ -29,8 +29,17 @@
             target = self.level[x + dx, y + dy]
         except IndexError:
             return
-        if target and target.block:
+        if target and target.block and not target.shove:
             return
+        if target and target.shove:
+            if dy:
+                return
+            if self.level.get_dirt((x + 2 * dx, y), True):
+                return
+            if self.level[x + 2 * dx, y] and self.level[x + 2 * dx, y].block:
+                return
+            target.animations.append(target.shove_anim(dx))
+            self.level.shove((x + dx, y), (dx, 0))
         self.hero.animations.append(self.hero.move_anim(dx, dy))
         self.dig((x + dx, y + dy))
         if target and target.pick:
@@ -47,7 +56,7 @@
         self.display.back_sprites.add(dirt)
 
     def die(self):
-        self.theme.stop()
+        # self.theme.stop()
         # self.eulogy.play()
         self.hero.animations.append(self.hero.death_anim())
 
@@ -71,12 +80,12 @@
                   self.level[x, y + 1] != self.hero):
                 if (not self.level.get_support((x - 1, y)) and
                     not self.level.get_support((x - 1, y + 1))):
-                    thing.animations.append(thing.roll_anim(-1))
+                    thing.animations.append(thing.slip_anim(-1))
                     self.level.shove((x, y), (-1, 1))
                     fell = True
                 elif (not self.level.get_support((x + 1, y)) and
                       not self.level.get_support((x + 1, y + 1))):
-                    thing.animations.append(thing.roll_anim(1))
+                    thing.animations.append(thing.slip_anim(1))
                     self.level.shove((x, y), (1, 1))
                     fell = True
             if fell:
@@ -91,7 +100,7 @@
         # self.theme.play(loops=-1)
         self.draw_map()
         self.display.refresh()
-        while True:
+        while self.hero.alive():
             self.clock.tick(self.fps)
             self.tick()
 
--- a/undermine/sprites.py	Sun Apr 27 14:49:31 2014 +0200
+++ b/undermine/sprites.py	Sun Apr 27 15:25:49 2014 +0200
@@ -9,6 +9,7 @@
     pick = False
     fall = False
     support = False
+    shove = False
 
     def __init__(self, image):
         super(Thing, self).__init__()
@@ -80,13 +81,14 @@
     block = True
     fall = True
     support = True
+    shove = True
 
     def fall_anim(self):
         for step in [1, 2, 4 , 8, 16, 32, 1]:
             self.rect.move_ip(0, step)
             yield None
 
-    def roll_anim(self, dx):
+    def slip_anim(self, dx):
         for step in range(4):
             self.rect.move_ip(dx * 10, 6)
             yield None
@@ -94,11 +96,18 @@
             self.rect.move_ip(dx * 6, 10)
             yield None
 
+    def shove_anim(self, dx):
+        for step in range(8):
+            self.rect.move_ip(dx * 8, 0)
+            yield None
+
+
 class Gem(Boulder):
     block = False
     pick = True
     fall = True
     support = True
+    shove = False
 
     def pick_anim(self):
         for step in [27, 9, 3, 1]: