Load items.
authorSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 18:03:24 +0000 (20:03 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 18:03:24 +0000 (20:03 +0200)
koperkapel/gamelib/items.py [new file with mode: 0644]
koperkapel/loaders/levelloader.py

diff --git a/koperkapel/gamelib/items.py b/koperkapel/gamelib/items.py
new file mode 100644 (file)
index 0000000..5aba919
--- /dev/null
@@ -0,0 +1,5 @@
+# Item utilities
+
+
+def get_item(item):
+    return item
index 601ea80b3609925d2ad5651ea333381be871970d..ccab73f1f017dc1000c94027687f4194a796b6cd 100644 (file)
@@ -9,16 +9,17 @@ from ..gamelib.level import Level
 from ..gamelib.door import Door
 from ..gamelib.keypad import Keypad
 from ..gamelib.friendlyroach import get_friendly_roach
+from ..gamelib.items import get_item
 
-        
 
 TILES = {
-    "cwall": Wall, # rename this everywhere
+    "cwall": Wall,  # rename this everywhere
     "floor": Floor,
     "tunnel": Tunnel,
     "underground": Underground,
 }
 
+
 class LevelLoader(ResourceLoader):
     """ Level loader. """
 
@@ -38,6 +39,7 @@ class LevelLoader(ResourceLoader):
         self._level.exit = level_data["exit"]
         self._level.enemies = []
         self._level.friends = []
+        self._level.items = []
         # Consistency check, so we can assume things are correct
         # in the level renderer
         for row, row_data in enumerate(self._level.tiles):
@@ -67,6 +69,8 @@ class LevelLoader(ResourceLoader):
         for pos in level_data['friendly roaches']:
             roach = get_friendly_roach(pos[0], pos[1])
             self._level.friends.append(roach)
+        for item in level_data['items']:
+            self._level.items.append(get_item(item))
         return self._level
 
     def _load_tile_images(self):
@@ -76,8 +80,8 @@ class LevelLoader(ResourceLoader):
                 neighborhood = self._level.get_neighbors(x, y)
                 for layer in ['floor', 'tunnels']:
                     neighbors = [x[layer] if x else None for x in neighborhood]
-                    tile['%s image' % layer] = \
-                            TILES[tile[layer]['base']].image(neighbors)
+                    tile['%s image' % layer] = (
+                            TILES[tile[layer]['base']].image(neighbors))
                     # Hack this for now
                     if self._level.is_exit(x, y):
                         tile['floor image'] = Exit.image(neighbors)