The endless pointlessness of level progression
authorNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 17:33:47 +0000 (19:33 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 17:36:14 +0000 (19:36 +0200)
koperkapel/gamelib/level.py
koperkapel/gamelib/tiles.py
koperkapel/images/fixtures/info.png
koperkapel/images/vehicles/walking/background.png
koperkapel/images/weapons/crowbar.png
koperkapel/images/weapons/gun.png
koperkapel/levels/level1.json
koperkapel/levels/level2.json
koperkapel/loaders/levelloader.py
koperkapel/scenes/base.py
koperkapel/scenes/level.py

index eb9e8b232e3ff6b5ec6aafafb8222df3685b3503..a754f29c80e996d9be2a238393116c9911805a42 100644 (file)
@@ -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"]
index fd47252b5cb861513a643d23a35666684266f56d..69ffbe83e901f174264eea8d37e086c8b36193bc 100644 (file)
@@ -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
index b59f4d7ebaeec725938aa340224f3362e4d40489..4fa8260b94ccf7cde1621d55eecc5948bb9faa33 100644 (file)
Binary files a/koperkapel/images/fixtures/info.png and b/koperkapel/images/fixtures/info.png differ
index 0a46fe1e954d04e0ca3108cc998acbee987107e1..36ef03c3f24f555bf57842205a587f7728348b00 100644 (file)
Binary files a/koperkapel/images/vehicles/walking/background.png and b/koperkapel/images/vehicles/walking/background.png differ
index a3fe54d05604278c9183ff2eec43782288890a9f..513b017f578eb5cecfce0eeae039aa4c85e59a8c 100644 (file)
Binary files a/koperkapel/images/weapons/crowbar.png and b/koperkapel/images/weapons/crowbar.png differ
index 70b2e79e3c1467365f37d5d4e63ed8c089654f81..f213c06286a5e4e573f3091c4ea5d9fa65e478dd 100644 (file)
Binary files a/koperkapel/images/weapons/gun.png and b/koperkapel/images/weapons/gun.png differ
index 69a3af4e8b2203a3d9d6dc3c45b74b46238ffafa..3833af515e0047e924bc518ccb9d1e11780fe99a 100644 (file)
    "starting pos": [
       5, 
       6
-   ], 
+   ],
+   "exit": {
+      "pos": [20, 3],
+      "next level": "level2"
+   },
    "friendly roaches": [
       [
          2, 
index 9fecec010f911739f9528744a7fdd50105196f50..238002d6799be0de2575f26c6617ebc24141017e 100644 (file)
    "starting pos": [
       1, 
       1
-   ], 
+   ],
+   "exit": {
+      "pos": [20, 3],
+      "next level": "level1"
+   },
    "friendly roaches": []
-}
\ No newline at end of file
+}
index 4c786572807ced5fb222420169d68f7ba66cece0..601ea80b3609925d2ad5651ea333381be871970d 100644 (file)
@@ -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))
 
index 623eb42a977276e506449831be35956d83758d32..24a8c615fa06c43f97fe893f302d5aab3197f26b 100644 (file)
@@ -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):
index a17de55d70ece5aa8a37e2bf88891580eadf728c..5da355f934aa3f0472a0219708cebe6860718cc6 100644 (file)
@@ -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')