Drop old weapon when picking up new one.
authorSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 19:37:00 +0000 (21:37 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 19:37:00 +0000 (21:37 +0200)
koperkapel/gamelib/items.py
koperkapel/scenes/level.py

index af66dd991e194f5abfa73540c7cf9a02c1b720b4..b61125016bb58b9707751ae655e9d031df5c6943 100644 (file)
@@ -29,3 +29,13 @@ def get_item(item):
     actor.game_pos = game_pos
     actor.anchor = (0, 0)
     return actor
+
+
+def clone_old_item(item, **new_data):
+    new_item = {
+        "type": item.item_type,
+        "pos": item.game_pos,
+    }
+    new_item.update(item.item_data)
+    new_item.update(new_data)
+    return get_item(new_item)
index 9b54435df80fb43151737a6c9f7d6421bb905cdf..a6844663caf020b5ffdafb3d9ad6c470ab677e14 100644 (file)
@@ -7,6 +7,7 @@ from ..loaders.levelloader import levels
 from .base import (
     Scene, ChangeSceneEvent, MoveViewportEvent, WorldEvent, defer_to_update)
 from ..constants import TILE_SIZE, WIDTH, HEIGHT
+from ..gamelib.items import clone_old_item
 from ..roaches import build_roach
 from ..vehicles.base import Vehicle
 
@@ -174,7 +175,12 @@ class GameLevelScene(BaseLevelScene):
         if item.item_type == "serum":
             world.serums.append(item.item_data["serum"])
         elif item.item_type == "weapon":
+            old_weapon = world.weapons.current
             world.weapons.current = item.item_data["weapon"]
+            if old_weapon != "spit":
+                clone = clone_old_item(item, weapon=old_weapon)
+                self._level.items.append(clone)
+                self._items.add(clone)
         self._vehicle_changed()
 
     @defer_to_update