From: Simon Cross Date: Sat, 5 Mar 2016 18:18:30 +0000 (+0200) Subject: Display a serum on level1. X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=0cc8d28563e4caeec279a0207ac160bb9fffb217;p=koperkapel.git Display a serum on level1. --- diff --git a/koperkapel/gamelib/items.py b/koperkapel/gamelib/items.py index 5aba919..837ccc6 100644 --- a/koperkapel/gamelib/items.py +++ b/koperkapel/gamelib/items.py @@ -1,5 +1,22 @@ # Item utilities +from ..serums import default_serums + + +def build_serum(item): + actor = default_serums.assemble(item["serum"]) + return actor + + +ITEM_TYPES = { + "serum": build_serum, +} + def get_item(item): - return item + item_type = item.pop("type") + game_pos = item.pop("pos") + actor = ITEM_TYPES[item_type](item) + actor.game_pos = game_pos + actor.anchor = (0, 0) + return actor diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index 5da355f..60e2305 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -90,11 +90,22 @@ class GameLevelScene(BaseLevelScene): super().enter(world) self._roaches = self.actors.add_layer("roaches", level=10) self._friends = self.actors.add_layer("friendly roaches", level=9) + self._items = self.actors.add_layer("items", level=9) self._vehicle = Vehicle.current(world) self._mode = 'walk' self._angle = 0 + self._init_items() + self._init_friendly_roaches() return self._init_roaches(world) + def _init_items(self): + for item in self._level.items: + self._items.add(item) + + def _init_friendly_roaches(self): + for friend in self._level.friends: + self._friends.add(friend) + def _init_roaches(self, world): x, y = self._level.start_pos self._level_layer = 'floor' @@ -102,8 +113,6 @@ class GameLevelScene(BaseLevelScene): self._set_pos(x, y) self._avatar.pos = (WIDTH // 2, HEIGHT // 2) self._roaches.add(self._avatar) - for friend in self._level.friends: - self._friends.add(friend) # Fix viewport offset return [ MoveViewportEvent(( @@ -152,6 +161,9 @@ class GameLevelScene(BaseLevelScene): for friend in self._friends: friend.pos = self.calc_offset( friend.game_pos[0] * TILE_SIZE, friend.game_pos[1] * TILE_SIZE) + for item in self._items: + item.pos = self.calc_offset( + item.game_pos[0] * TILE_SIZE, item.game_pos[1] * TILE_SIZE) return events def _movement_key(self, key):