From: Simon Cross Date: Sat, 5 Mar 2016 18:03:24 +0000 (+0200) Subject: Load items. X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=58c1d4f2c0a0dc8b36689aa8deb0542346e2b4ad;p=koperkapel.git Load items. --- diff --git a/koperkapel/gamelib/items.py b/koperkapel/gamelib/items.py new file mode 100644 index 0000000..5aba919 --- /dev/null +++ b/koperkapel/gamelib/items.py @@ -0,0 +1,5 @@ +# Item utilities + + +def get_item(item): + return item diff --git a/koperkapel/loaders/levelloader.py b/koperkapel/loaders/levelloader.py index 601ea80..ccab73f 100644 --- a/koperkapel/loaders/levelloader.py +++ b/koperkapel/loaders/levelloader.py @@ -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)