From 060a5fe465657afdf24712a8cabbf1c9c2a46ea9 Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 18 Apr 2013 15:43:31 +0200 Subject: [PATCH] Load correct images for gate and buttons --- erdslangetjie/level.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/erdslangetjie/level.py b/erdslangetjie/level.py index 2974b88..c722b56 100644 --- a/erdslangetjie/level.py +++ b/erdslangetjie/level.py @@ -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 -- 2.34.1