From b4d8e05a494cd8f270eb60efea35b69c16933029 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 5 Mar 2016 21:37:00 +0200 Subject: [PATCH] Drop old weapon when picking up new one. --- koperkapel/gamelib/items.py | 10 ++++++++++ koperkapel/scenes/level.py | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/koperkapel/gamelib/items.py b/koperkapel/gamelib/items.py index af66dd9..b611250 100644 --- a/koperkapel/gamelib/items.py +++ b/koperkapel/gamelib/items.py @@ -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) diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index 9b54435..a684466 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -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 -- 2.34.1