From: Neil Date: Sat, 5 Mar 2016 17:33:47 +0000 (+0200) Subject: The endless pointlessness of level progression X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=31ec0ae3dc918618849b41c4df6b064d6a47c69f;p=koperkapel.git The endless pointlessness of level progression --- diff --git a/koperkapel/gamelib/level.py b/koperkapel/gamelib/level.py index eb9e8b2..a754f29 100644 --- a/koperkapel/gamelib/level.py +++ b/koperkapel/gamelib/level.py @@ -14,6 +14,7 @@ class Level(object): self.grates = [] self.tileset = None self.start_pos = (0, 0) + self.exit = None self.enemies = [] self.friends = [] @@ -74,3 +75,9 @@ class Level(object): self.friends.remove(friend) return friend return None + + def is_exit(self, x, y): + return self.exit and (x, y) == tuple(self.exit["pos"]) + + def get_exit_level(self): + return self.exit["next level"] diff --git a/koperkapel/gamelib/tiles.py b/koperkapel/gamelib/tiles.py index fd47252..69ffbe8 100644 --- a/koperkapel/gamelib/tiles.py +++ b/koperkapel/gamelib/tiles.py @@ -64,6 +64,12 @@ class Grate(Tile): IMG = os.path.join('grate', 'grate') TILESET = 'bunker' + +class Exit(Tile): + IMG = os.path.join('exit', 'exit') + TILESET = 'bunker' + + class Tunnel(OrientatedTile): @classmethod diff --git a/koperkapel/images/fixtures/info.png b/koperkapel/images/fixtures/info.png index b59f4d7..4fa8260 100644 Binary files a/koperkapel/images/fixtures/info.png and b/koperkapel/images/fixtures/info.png differ diff --git a/koperkapel/images/vehicles/walking/background.png b/koperkapel/images/vehicles/walking/background.png index 0a46fe1..36ef03c 100644 Binary files a/koperkapel/images/vehicles/walking/background.png and b/koperkapel/images/vehicles/walking/background.png differ diff --git a/koperkapel/images/weapons/crowbar.png b/koperkapel/images/weapons/crowbar.png index a3fe54d..513b017 100644 Binary files a/koperkapel/images/weapons/crowbar.png and b/koperkapel/images/weapons/crowbar.png differ diff --git a/koperkapel/images/weapons/gun.png b/koperkapel/images/weapons/gun.png index 70b2e79..f213c06 100644 Binary files a/koperkapel/images/weapons/gun.png and b/koperkapel/images/weapons/gun.png differ diff --git a/koperkapel/levels/level1.json b/koperkapel/levels/level1.json index 69a3af4..3833af5 100644 --- a/koperkapel/levels/level1.json +++ b/koperkapel/levels/level1.json @@ -4337,7 +4337,11 @@ "starting pos": [ 5, 6 - ], + ], + "exit": { + "pos": [20, 3], + "next level": "level2" + }, "friendly roaches": [ [ 2, diff --git a/koperkapel/levels/level2.json b/koperkapel/levels/level2.json index 9fecec0..238002d 100644 --- a/koperkapel/levels/level2.json +++ b/koperkapel/levels/level2.json @@ -7628,6 +7628,10 @@ "starting pos": [ 1, 1 - ], + ], + "exit": { + "pos": [20, 3], + "next level": "level1" + }, "friendly roaches": [] -} \ No newline at end of file +} diff --git a/koperkapel/loaders/levelloader.py b/koperkapel/loaders/levelloader.py index 4c78657..601ea80 100644 --- a/koperkapel/loaders/levelloader.py +++ b/koperkapel/loaders/levelloader.py @@ -4,7 +4,7 @@ import json from pgzero.loaders import ResourceLoader -from ..gamelib.tiles import Wall, Floor, Tunnel, Underground, Grate +from ..gamelib.tiles import Wall, Floor, Tunnel, Underground, Grate, Exit from ..gamelib.level import Level from ..gamelib.door import Door from ..gamelib.keypad import Keypad @@ -35,6 +35,7 @@ class LevelLoader(ResourceLoader): self._level.tiles = level_data['tiles'] self._level.tileset = level_data['tileset'] self._level.start_pos = level_data["starting pos"] + self._level.exit = level_data["exit"] self._level.enemies = [] self._level.friends = [] # Consistency check, so we can assume things are correct @@ -78,7 +79,9 @@ class LevelLoader(ResourceLoader): tile['%s image' % layer] = \ TILES[tile[layer]['base']].image(neighbors) # Hack this for now - if layer == 'floor' and 'crawl' in tile[layer]['behaviour']: + if self._level.is_exit(x, y): + tile['floor image'] = Exit.image(neighbors) + elif layer == 'floor' and 'crawl' in tile[layer]['behaviour']: tile['floor image'] = Grate.image(neighbors) self._level.grates.append((x, y)) diff --git a/koperkapel/scenes/base.py b/koperkapel/scenes/base.py index 623eb42..24a8c61 100644 --- a/koperkapel/scenes/base.py +++ b/koperkapel/scenes/base.py @@ -29,8 +29,10 @@ class Engine: ev.apply(self) def change_scene(self, scene): + print('here', self._scene) self._apply_events(self._scene.exit(self._world.proxy())) self._scene = scene + print('there', self._scene) self._apply_events(self._scene.enter(self._world.proxy())) def change_world(self, *args, **kw): diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index a17de55..5da355f 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -4,7 +4,7 @@ from pgzero.constants import keys from pygame import Surface import pygame.locals as pgl from ..loaders.levelloader import levels -from .base import Scene, ChangeSceneEvent, MoveViewportEvent, defer_to_update +from .base import Scene, ChangeSceneEvent, MoveViewportEvent, WorldEvent, defer_to_update from ..constants import TILE_SIZE, WIDTH, HEIGHT from ..roaches import build_roach from ..vehicles.base import Vehicle @@ -84,6 +84,7 @@ class BaseLevelScene(Scene): class GameLevelScene(BaseLevelScene): def enter(self, world): + print('enter', world['level']['name'], self._level) if self._level is not None: return super().enter(world) @@ -187,6 +188,9 @@ class GameLevelScene(BaseLevelScene): friend = self._level.remove_friend(x, y) self._friends.remove(friend) self._add_roach() + elif self._level.is_exit(x, y): + next_level = self._level.get_exit_level() + return [WorldEvent('set', {'level.name': next_level}), ChangeSceneEvent(GameLevelScene())] def _fire_key(self): print('Boom')