seat_actor.pos = (
seat.vehicle_pos[0] + VEHICLE_MID_X,
seat.vehicle_pos[1] + VEHICLE_MID_Y)
+ self._seat_layer[self._seat_pos].selected = True
def _init_roaches(self, world):
self._roach_actors = {}
def _inventory_right(self):
self._inventory_pos += 1
+ def _select_seat(self, seat_pos):
+ self._seat_layer[self._seat_pos].selected = False
+ self._seat_pos = seat_pos
+ self._seat_layer[self._seat_pos].selected = True
+
def _eject_roach(self):
print("Eject roach.")
if button == mouse.LEFT:
for actor in self.actors.buttons:
if actor.collidepoint(pos):
- actor.action()
- break
+ return actor.action()
+ for i, actor in enumerate(self.actors.seats):
+ if actor.collidepoint(pos):
+ return self._select_seat(i)
""" Base class for vehicles. """
+from pygame.constants import BLEND_RGBA_MULT
from pgzero.actor import Actor
+from pgzero.loaders import images
+from ..actors.orientatedsurf import OrientatedSurfActor
class Vehicle:
vehicle_type = None
approximate_radius = 200
+ selected_seat_overlay_color = (255, 0, 0, 255)
def __init__(self):
self.seats = self.init_seats()
self.vehicle_pos = (pos[0] * vrad, pos[1] * vrad)
def actor(self):
- return Actor("vehicles/%s/seat" % (self.vehicle.vehicle_type,))
+ seat = images.load(
+ "vehicles/%s/seat" % (self.vehicle.vehicle_type,))
+ selected_seat = seat.copy()
+ selected_seat.fill(
+ self.vehicle.selected_seat_overlay_color, None, BLEND_RGBA_MULT)
+ return SeatActor(seat, selected_seat)
+
+
+class SeatActor(OrientatedSurfActor):
+ def __init__(self, seat, selected_seat):
+ self._selected = False
+ self._seat = seat
+ self._selected_seat = selected_seat
+ super().__init__(surf=self._seat, angle=0)
+
+ @property
+ def selected(self):
+ return self._selected
+
+ @selected.setter
+ def selected(self, value):
+ self._selected = value
+ self.surf = self._selected_seat if value else self._seat
Vehicle.register_all()