self._closed = False
self.surf = self._open_surf
+ def close(self):
+ self._closed = True
+ self.surf = self._closed_surf
+
def is_closed(self):
return self._closed
surf = images.load(os.path.join('fixtures', 'keypad'))
super().__init__(surf, anchor=(0, 0))
- def activate(self):
+ def activate(self, roaches):
# FIXME: Check stats
for door in self._doors:
- door.open()
+ if door.is_closed():
+ door.open()
+ else:
+ door.close()
self.tiles = []
self.keypads = []
self.doors = []
+ self.grates = []
self.tileset = None
self.start_pos = (0, 0)
def can_crawl(self, x, y, layer):
return 'crawl' in self.tiles[y][x][layer]['behaviour']
- def keypad_at(self, x, y):
+ def is_keypad(self, x, y):
for keypad in self.keypads:
if (x, y) == keypad.game_pos:
- return keypad
- return None
+ return True
+ return False
+
+ def is_grate(self, x, y):
+ if (x, y) in self.grates:
+ return True
+ return False
+
+ def press_keypad(self, x, y, roaches):
+ for keypad in self.keypads:
+ if (x, y) == keypad.game_pos:
+ keypad.activate(roaches)
angle = 0
new_door = Door(x, y, angle)
self._level.doors.append(new_door)
+ doors.append(new_door)
# Add the keypads
for keypad in door_info['keypads']:
new_keypad = Keypad(keypad[0], keypad[1], doors)
TILES[tile[layer]['base']].image(neighbors)
# Hack this for now
if layer == 'floor' and 'crawl' in tile[layer]['behaviour']:
- print('Here')
tile['floor image'] = Grate.image(neighbors)
+ self._level.grates.append((x, y))
levels = LevelLoader('levels')
self._set_pos(x + 1, y)
offset = (TILE_SIZE, 0)
self._set_angle(270)
- elif key == keys.S:
- if self._level_layer == 'floor' and self._level.can_crawl(x, y, 'floor'):
- # We're probably on a grate
- if self._level.can_crawl(x, y, 'tunnels'):
- self._level_layer = 'tunnels'
- self._mode = 'crawl'
- elif self._level.can_crawl(x, y, 'floor'):
- # Must be in the tunnels already
- self._level_layer = 'floor'
- self._mode = 'walk'
+ elif key == keys.C:
+ # Activate
+ if self._level.is_grate(x, y):
+ if self._level_layer == 'floor' and self._level.can_crawl(x, y, 'floor'):
+ if self._level.can_crawl(x, y, 'tunnels'):
+ self._level_layer = 'tunnels'
+ self._mode = 'crawl'
+ elif self._level.can_crawl(x, y, 'floor'):
+ # Must be in the tunnels already
+ self._level_layer = 'floor'
+ self._mode = 'walk'
+ elif self._level.is_keypad(x, y):
+ self._level.press_keypad(x, y, self._roaches)
return
+ elif key == keys.X:
+ # Fire
+ print('Boom')
+ elif key == keys.V:
+ # Leave vehicle
+ print('Vehicle key pressed')
+
if offset:
return [MoveViewportEvent(offset)]
return super(GameLevelScene, self).on_key_down(key, mod, unicode)