changeset 13:013da0287d6e

death
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sat, 26 Apr 2014 22:23:03 +0200
parents 65a5820c3fee
children c46db4de8d20
files undermine/game.py undermine/sprites.py
diffstat 2 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/undermine/game.py	Sat Apr 26 22:11:31 2014 +0200
+++ b/undermine/game.py	Sat Apr 26 22:23:03 2014 +0200
@@ -10,13 +10,13 @@
 import undermine.sprites
 
 
-MAP_DIRT, MAP_TUNNEL, MAP_BOULDER, MAP_GEM, MAP_PLAYER = range(5)
+MAP_DIRT, MAP_TUNNEL, MAP_BOULDER, MAP_GEM, MAP_HERO = range(5)
 TILES = {
     MAP_DIRT: 12,
     MAP_TUNNEL: 15,
     MAP_BOULDER: 15,
     MAP_GEM: 15,
-    MAP_PLAYER: 15,
+    MAP_HERO: 15,
 }
 
 
@@ -45,7 +45,7 @@
                 if boulder.pos == (x + dx, y + dy):
                     boulder.animations.append(boulder.pick_anim())
                     break
-        self.map[y + dy][x + dx] = MAP_PLAYER
+        self.map[y + dy][x + dx] = MAP_HERO
         self.map[y][x] = MAP_TUNNEL
 
     def dig(self, (x, y)):
@@ -55,6 +55,9 @@
         dirt.place((x, y))
         self.display.back_sprites.add(dirt)
 
+    def die(self):
+        self.hero.animations.append(self.hero.death_anim())
+
     def make_map(self, map_size):
         self.boulders = pygame.sprite.Group()
         squares = []
@@ -68,7 +71,7 @@
         self.hero = undermine.sprites.Hero(self.images)
         self.hero.place(squares.pop())
         self.display.sprites.add(self.hero)
-        self.map[self.hero.pos[1]][self.hero.pos[0]] = MAP_PLAYER
+        self.map[self.hero.pos[1]][self.hero.pos[0]] = MAP_HERO
         for i in range(8):
             boulder = undermine.sprites.Boulder(self.images[4])
             x, y = squares.pop()
@@ -96,11 +99,13 @@
             if boulder.animations:
                 continue
             x, y = boulder.pos
+            fell = False
             if y + 1 < len(self.map) and self.map[y + 1][x] == MAP_TUNNEL:
                 boulder.animations.append(boulder.fall_anim())
                 self.map[y + 1][x] = self.map[y][x]
                 self.map[y][x] = MAP_TUNNEL
                 boulder.place((x, y +1), False)
+                fell = True
             elif (y + 1 < len(self.map) and
                   self.map[y + 1][x] in (MAP_BOULDER, MAP_GEM)):
                 if (x > 0 and
@@ -110,6 +115,7 @@
                     self.map[y + 1][x - 1] = self.map[y][x]
                     self.map[y][x] = MAP_TUNNEL
                     boulder.place((x - 1, y + 1), False)
+                    fell = True
                 elif (x + 1 < len(self.map[0]) and
                       self.map[y][x + 1] == MAP_TUNNEL and
                       self.map[y + 1][x + 1] == MAP_TUNNEL):
@@ -117,6 +123,10 @@
                     self.map[y + 1][x + 1] = self.map[y][x]
                     self.map[y][x] = MAP_TUNNEL
                     boulder.place((x + 1, y + 1), False)
+                    fell = True
+            if (fell and y +2 < len(self.map) and
+                self.map[y + 2][x] == MAP_HERO):
+                    self.die()
 
     def run(self):
         self.draw_map()
--- a/undermine/sprites.py	Sat Apr 26 22:11:31 2014 +0200
+++ b/undermine/sprites.py	Sat Apr 26 22:23:03 2014 +0200
@@ -56,6 +56,14 @@
             yield None
         self.ready = True
 
+    def death_anim(self):
+        for step in range(4):
+            yield None
+        self.image = self.images[3]
+        for step in range(4):
+            yield None
+        self.kill()
+
 
 class Boulder(Animated):
     def fall_anim(self):