Display a serum on level1.
authorSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 18:18:30 +0000 (20:18 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 18:18:30 +0000 (20:18 +0200)
koperkapel/gamelib/items.py
koperkapel/scenes/level.py

index 5aba919d8dda70285331beab999d84e70cbd62ea..837ccc61a58886f3ffa062b1e0870c669bc18592 100644 (file)
@@ -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
index 5da355f934aa3f0472a0219708cebe6860718cc6..60e230568575670baa72e1de4a4d3f1ffce1dab2 100644 (file)
@@ -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):