From: Neil Date: Sat, 5 Mar 2016 12:17:46 +0000 (+0200) Subject: Doors can open (and also close) X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=086b92efc52a09908e7186b906f6ca6dfb1607e6;p=koperkapel.git Doors can open (and also close) --- diff --git a/koperkapel/gamelib/door.py b/koperkapel/gamelib/door.py index 9b6e563..3134e1c 100644 --- a/koperkapel/gamelib/door.py +++ b/koperkapel/gamelib/door.py @@ -19,5 +19,9 @@ class Door(OrientatedSurfActor): 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 diff --git a/koperkapel/gamelib/keypad.py b/koperkapel/gamelib/keypad.py index 4667fcd..b328f39 100644 --- a/koperkapel/gamelib/keypad.py +++ b/koperkapel/gamelib/keypad.py @@ -14,7 +14,10 @@ class Keypad(SurfActor): 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() diff --git a/koperkapel/gamelib/level.py b/koperkapel/gamelib/level.py index 39e4565..a8fe447 100644 --- a/koperkapel/gamelib/level.py +++ b/koperkapel/gamelib/level.py @@ -11,6 +11,7 @@ class Level(object): self.tiles = [] self.keypads = [] self.doors = [] + self.grates = [] self.tileset = None self.start_pos = (0, 0) @@ -43,8 +44,18 @@ class Level(object): 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) diff --git a/koperkapel/loaders/levelloader.py b/koperkapel/loaders/levelloader.py index 9bb85e4..5247695 100644 --- a/koperkapel/loaders/levelloader.py +++ b/koperkapel/loaders/levelloader.py @@ -55,6 +55,7 @@ class LevelLoader(ResourceLoader): 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) @@ -72,8 +73,8 @@ class LevelLoader(ResourceLoader): 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') diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index 70dd7be..ea37e15 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -129,17 +129,27 @@ class GameLevelScene(BaseLevelScene): 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)