from ..serums import default_serums
from ..weapons import default_weapons
+from ..vehicles.base import Vehicle
def build_serum(item):
actor = default_weapons.assemble(item["weapon"])
return actor
+def build_vehicle(item):
+ actor = Vehicle.by_type(item["vehicle"]).get_avatar(dead=True)
+ return actor
+
ITEM_BUILDERS = {
"serum": build_serum,
"weapon": build_weapon,
+ "vehicle": build_vehicle,
}
new_item.update(item.item_data)
new_item.update(new_data)
return get_item(new_item)
+
+
+def create_new_item(item_type, pos, **kwd):
+ new_item = {
+ "type": item_type,
+ "pos": pos,
+ }
+ new_item.update(kwd)
+ return get_item(new_item)
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 ..gamelib.items import clone_old_item, create_new_item
from ..roaches import build_roach
from ..vehicles.base import Vehicle
from ..weapons import weapon_by_name
@defer_to_update
def _change_vehicle(self, world):
- vehicle = Vehicle.random()
- world.vehicles.current = vehicle
+ x, y = self._player_pos
+
+ old_vehicle = world.vehicles.current
+
+ item = self._level.item_at(x, y)
+
+ if item and item.item_type == "vehicle":
+ world.vehicles.current = item.item_data["vehicle"]
+ self._level.remove_item(item)
+ self._items.remove(item)
+ else:
+ world.vehicles.current = "walking"
+
+ if old_vehicle != "walking":
+ dropped_vehicle = create_new_item("vehicle", (x, y), vehicle=old_vehicle)
+ self._level.items.append(dropped_vehicle)
+ self._items.add(dropped_vehicle)
+
self._vehicle_changed()
def update(self, world, engine, dt):
self._add_roach()
elif self._level.item_at(x, y):
item = self._level.item_at(x, y)
- self._level.remove_item(item)
- self._items.remove(item)
- self._gain_item(item)
+ if item.item_type != "vehicle":
+ self._level.remove_item(item)
+ self._items.remove(item)
+ self._gain_item(item)
elif self._level.is_exit(x, y):
next_level = self._level.get_exit_level()
return [
vehicle = images.load(safepath("vehicle%s/%s_%d") % (
suffix, self.vehicle_type, i + 1))
frame = vehicle.copy()
- frame.blit(weapon.surf, (0, 0))
+ if weapon:
+ frame.blit(weapon.surf, (0, 0))
return frame
- def get_avatar(self, world):
- weapon = default_weapons.assemble(
+ def get_avatar(self, world=None, dead=False):
+ if not dead:
+ weapon = default_weapons.assemble(
world.weapons.current, tape=self.weapons_taped_on)
- frames = [self._avatar_frame(i, weapon) for i in range(4)]
+ frames = [self._avatar_frame(i, weapon) for i in range(4)]
+ else:
+ frames = [self._avatar_frame(0, weapon=None)]
return AnimatedSurfActor(frames, anchor=(0, 0))