Load correct images for gate and buttons
authorNeil <neil@dip.sun.ac.za>
Thu, 18 Apr 2013 13:43:31 +0000 (15:43 +0200)
committerNeil <neil@dip.sun.ac.za>
Thu, 18 Apr 2013 13:43:31 +0000 (15:43 +0200)
erdslangetjie/level.py

index 2974b88b349adddc1bda0e41e072b0978f0d177b..c722b563873c76034e73548e2a723c1ba0cfdf14 100644 (file)
@@ -43,10 +43,6 @@ class Level(object):
             self._tiles.append(tile_line)
 
     def _get_tile_image(self, pos, c):
-        if pos in self._gates:
-            del self._gates[pos]
-        if pos in self._buttons:
-            del self._buttons[pos]
         image = None
         if c == FLOOR:
             image = load_image('tiles/floor.png')
@@ -59,8 +55,25 @@ class Level(object):
             self.exit_pos.append(pos)
             image = load_image('tiles/door.png')
         elif c == GATE:
-            image = load_image('tiles/gate_down.png')
-            self._gates[pos] = -1  # down
+            if pos not in self._gates:
+                self._gates[pos] = -1  # down
+                image = load_image('tiles/gate_down.png')
+            else:
+                state = self._gates[pos]
+                if state == -1:
+                    image = load_image('tiles/gate_down.png')
+                elif state == 0:
+                    # destroyed
+                    image = load_image('tiles/floor.png')
+                elif state == 1:
+                    # badly damaged
+                    image = load_image('tiles/gate_dented.png')
+                elif state == 2:
+                    # lightly damaged
+                    image = load_image('tiles/gate_bent.png')
+                else:
+                    # gate up
+                    image = load_image('tiles/gate_up.png')
         elif c == BUTTON:
             image = load_image('tiles/button.png')
             self._buttons[pos] = 'active'
@@ -93,6 +106,11 @@ class Level(object):
         return self._data[pos[1]][pos[0]]
 
     def set_tile_type(self, pos, new_type):
+        # Setting the type resets any state anyway, so
+        if pos in self._gates:
+            del self._gates[pos]
+        if pos in self._buttons:
+            del self._buttons[pos]
         self._data[pos[1]][pos[0]] = new_type
         new_tile = self._get_tile_image(pos, new_type)
         self._tiles[pos[1]][pos[0]] = new_tile
@@ -193,7 +211,7 @@ class Level(object):
         if tile == WALL or tile == ENTRY:
             return True
         if tile == GATE:
-            if self._gates[pos] != 'down':
+            if self._gates[pos] != -1:
                 return True
         return False