""" Roach management scene. """
+from pygame.constants import BLEND_RGBA_MULT, BLEND_RGBA_SUB
from pgzero.constants import keys, mouse
from pgzero.actor import Actor
from pgzero.screen import Screen
from ..roaches import big_roaches, roach_by_name
from ..serums import big_serums, roach_is_serumless, SERUMS
from ..vehicles.base import Vehicle
-from .base import Scene, ChangeSceneEvent
+from .base import Scene, ChangeSceneEvent, defer_to_update
TOOLBAR_LEFT_X = WIDTH * 3 // 4
def enter(self, world):
self._vehicle = Vehicle.current(world)
- self._update_calls = []
self._init_bg()
self._init_seats()
self._init_roaches(world)
def _init_bg(self):
self.actors.default.clear()
- overlay = self._vehicle.roach_management_overlay()._surf
+ overlay = self._vehicle.roach_management_overlay()
base = overlay.copy()
if self._level_scene is not None:
base.fill((0, 0, 0))
else:
base.fill((10, 10, 10))
base.blit(overlay, (0, 0))
+ frame = self._vehicle.roach_management_frame()
+ if frame is not None:
+ frame = frame.copy()
+ frame.fill((255, 255, 255, 8), None, BLEND_RGBA_MULT)
+ frame_rect = frame.get_rect()
+ base.blit(frame, (
+ VEHICLE_MID_X - frame_rect.w // 2,
+ VEHICLE_MID_Y - frame_rect.h // 2),
+ None, BLEND_RGBA_SUB)
self.actors.default.add(SurfActor(base))
def _init_seats(self):
self._seat_pos = seat_pos
self._seat_layer[self._seat_pos].selected = True
- def _eject_roach(self, world=None):
- if world is None:
- self._update_calls.append(self._eject_roach)
- return
+ @defer_to_update
+ def _eject_roach(self, world):
self._vehicle.seat_roach(world, None, self._seat_pos)
- def _click_roach_pad(self, world=None):
- if world is None:
- self._update_calls.append(self._click_roach_pad)
- return
+ @defer_to_update
+ def _click_roach_pad(self, world):
if self._outside_roaches:
roach = self._outside_roaches[self._outside_roach_pos]
self._vehicle.seat_roach(world, roach, self._seat_pos)
- def _click_inventory_pad(self, world=None):
- if world is None:
- self._update_calls.append(self._click_inventory_pad)
- return
+ @defer_to_update
+ def _click_inventory_pad(self, world):
roach_name = self._vehicle.roach_at(world, self._seat_pos)
if roach_name is None:
return
if roach_is_serumless(roach):
roach[serum] = True
world.serums = serums
- self._update_calls.append((self._update_roach_actor, roach_name))
+ self._update_roach_actor(roach_name)
+ @defer_to_update
def _update_roach_actor(self, world, roach_name):
roach = roach_by_name(world, roach_name)
self._roach_actors[roach_name] = big_roaches.assemble(roach)
def update(self, world, engine, dt):
- update_calls, self._update_calls = self._update_calls, []
- while update_calls:
- f, args = update_calls.pop(), ()
- if type(f) is tuple:
- f, args = f[0], f[1:]
- f(world, *args)
+ super().update(world, engine, dt)
events = world.pop_events()
self._update_inventory(world)
self._update_roaches(world)