X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=koperkapel%2Fscenes%2Flevel.py;h=ea37e154ed643a39f166a1fcd8ada72553fd8af3;hb=086b92efc52a09908e7186b906f6ca6dfb1607e6;hp=a800ba0d842d0f5c3d130b16acbef92f6c0aa958;hpb=d436671e45a50d49728388e6ee7269922a36873c;p=koperkapel.git diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index a800ba0..ea37e15 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -21,6 +21,13 @@ class BaseLevelScene(Scene): for layer in ['floor', 'tunnels']: self._surfaces[layer] = self._render(layer) self._overlay = self._surfaces['floor'].copy() + self._doors = self.actors.add_layer("doors", level=9) + self._keypads = self.actors.add_layer("keypads", level=8) + # These are already Actors + for door in self._level.doors: + self._doors.add(door) + for keypad in self._level.keypads: + self._keypads.add(keypad) def _render(self, layer): # We cache the rendered surface to avoid doing a large number @@ -38,6 +45,13 @@ class BaseLevelScene(Scene): surface.blit(tile[layer_key], pos) return surface.convert_alpha() + def update(self, world, engine, dt): + """Fix the door and keypad positions""" + for door in self._doors: + door.pos = engine.calc_offset(door.game_pos[0] * TILE_SIZE, door.game_pos[1] * TILE_SIZE) + for keypad in self._keypads: + keypad.pos = engine.calc_offset(keypad.game_pos[0] * TILE_SIZE, keypad.game_pos[1] * TILE_SIZE) + def draw(self, screen, viewport): screen.clear() # Viewport is the position of the screen relative to the @@ -62,47 +76,80 @@ class GameLevelScene(BaseLevelScene): def enter(self, world): super().enter(world) self._roaches = self.actors.add_layer("roaches", level=10) - self._init_roaches(world.roaches) + self._mode = 'walk' + return self._init_roaches(world.roaches) def _init_roaches(self, roaches): - x, y = self._level.start_pos for roach in roaches: roach_actor = self._roaches.add(default_roaches.assemble(roach)) roach_actor.anchor = (0, 0) - roach_actor.pos = (x * TILE_SIZE, y * TILE_SIZE) + roach_actor.pos = (WIDTH // 2, HEIGHT // 2) + x, y = self._level.start_pos self._set_pos(x, y) self._level_layer = 'floor' + # Fix viewport offset + return [MoveViewportEvent((x * TILE_SIZE - WIDTH // 2, y * TILE_SIZE - HEIGHT // 2))] def _set_pos(self, x, y): self._player_pos = (x, y) + print('Now at ', x, y) + + def _can_move(self, x, y): + if self._mode == 'walk': + return self._level.can_walk(x, y, self._level_layer) + elif self._mode == 'fly': + return self._level.can_fly(x, y, self._level_layer) + elif self._mode == 'crawl': + return self._level.can_crawl(x, y, self._level_layer) + + def _set_angle(self, angle): + for roach in self._roaches: + roach.angle = angle def on_key_down(self, key, mod, unicode): offset = None x, y = self._player_pos if key == keys.DOWN: - if self._level.can_walk(x, y + 1, self._level_layer): + if self._can_move(x, y + 1): self._set_pos(x, y + 1) offset = (0, TILE_SIZE) + self._set_angle(180) elif key == keys.UP: - if self._level.can_walk(x, y - 1, self._level_layer): + if self._can_move(x, y - 1): self._set_pos(x, y - 1) offset = (0, -TILE_SIZE) + self._set_angle(0) elif key == keys.LEFT: - if self._level.can_walk(x - 1, y, self._level_layer): + if self._can_move(x - 1, y): self._set_pos(x - 1, y) offset = (-TILE_SIZE, 0) + self._set_angle(90) elif key == keys.RIGHT: - if self._level.can_walk(x + 1, y, self._level_layer): + if self._can_move(x + 1, y): self._set_pos(x + 1, y) offset = (TILE_SIZE, 0) - elif key == keys.S: - if self._level_layer == 'floor': - if self._level.can_walk(x, y, 'tunnels'): - self._level_layer = 'tunnels' - elif self._level.can_walk(x, y, 'floor'): - # Must be in the tunnels already - self._level_layer = 'floor' + self._set_angle(270) + 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)