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')
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'
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
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