X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=koperkapel%2Fscenes%2Flevel.py;h=a6844663caf020b5ffdafb3d9ad6c470ab677e14;hb=ed7b7dbe49f3962132f0db806552a5873d6fc113;hp=606a0db038b1dae954e1d51d57e6826c862ab24b;hpb=3e3bc411ef3560d254c9e4de10f8adf818ae3850;p=koperkapel.git diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index 606a0db..a684466 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -4,8 +4,10 @@ from pgzero.constants import keys from pygame import Surface import pygame.locals as pgl from ..loaders.levelloader import levels -from .base import Scene, ChangeSceneEvent, MoveViewportEvent, WorldEvent, defer_to_update +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 @@ -115,8 +117,9 @@ class GameLevelScene(BaseLevelScene): def exit(self, world): for generator in self._generators: - # We don't want these running while we're on other levels, but we don't want to delete them - # here either (because of the vehicle management view) + # We don't want these running while we're on other levels, but we + # don't want to delete them here either (because of the vehicle + # management view) generator.pause() def _init_generators(self): @@ -167,6 +170,19 @@ class GameLevelScene(BaseLevelScene): world.roaches.append(build_roach(world)) self._vehicle_changed() + @defer_to_update + def _gain_item(self, world, item): + 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 def _change_vehicle(self, world): vehicle = Vehicle.random() @@ -204,7 +220,8 @@ class GameLevelScene(BaseLevelScene): (keys.RIGHT, (1, 0), -90), ): if key == k: - if self._angle == angle and self._last_key_down > self._key_rate: + if (self._angle == angle and + self._last_key_down > self._key_rate): nx, ny = x + dp[0], y + dp[1] if self._can_move(nx, ny): self._set_pos(nx, ny) @@ -230,13 +247,21 @@ class GameLevelScene(BaseLevelScene): self._mode = 'walk' elif self._level.is_keypad(x, y): self._level.press_keypad(x, y, self._roaches) - elif self._level.is_on_friend(x, y): - friend = self._level.remove_friend(x, y) + elif self._level.friend_at(x, y): + friend = self._level.friend_at(x, y) + self._level.remove_friend(friend) self._friends.remove(friend) 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) elif self._level.is_exit(x, y): next_level = self._level.get_exit_level() - return [WorldEvent('set', {'level.name': next_level}), ChangeSceneEvent(GameLevelScene())] + return [ + WorldEvent('set', {'level.name': next_level}), + ChangeSceneEvent(GameLevelScene())] def _fire_key(self, dt): if self._last_key_down > self._key_rate: @@ -252,7 +277,8 @@ class GameLevelScene(BaseLevelScene): if key in (keys.DOWN, keys.UP, keys.LEFT, keys.RIGHT): self._held_keys.clear() self._held_keys.add(key) - # We do this so pressing the key has an instant effect, and can then be held + # We do this so pressing the key has an instant effect, and can + # then be held self._last_key_down = self._key_rate + 0.01 return self._movement_key(key, 0.01) elif key == keys.C: