From 73f160f2e18b0fde0bab8490f0e86fe78663b7aa Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 5 Mar 2016 14:12:37 +0200 Subject: [PATCH] Selectable seats. --- koperkapel/scenes/roach_management.py | 12 ++++++++++-- koperkapel/vehicles/base.py | 28 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/koperkapel/scenes/roach_management.py b/koperkapel/scenes/roach_management.py index 21fc37c..7dc9c5e 100644 --- a/koperkapel/scenes/roach_management.py +++ b/koperkapel/scenes/roach_management.py @@ -64,6 +64,7 @@ class RoachesScene(Scene): 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 = {} @@ -157,6 +158,11 @@ class RoachesScene(Scene): 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.") @@ -173,5 +179,7 @@ class RoachesScene(Scene): 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) diff --git a/koperkapel/vehicles/base.py b/koperkapel/vehicles/base.py index f4506d6..9aff447 100644 --- a/koperkapel/vehicles/base.py +++ b/koperkapel/vehicles/base.py @@ -1,6 +1,9 @@ """ 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: @@ -8,6 +11,7 @@ class Vehicle: vehicle_type = None approximate_radius = 200 + selected_seat_overlay_color = (255, 0, 0, 255) def __init__(self): self.seats = self.init_seats() @@ -66,7 +70,29 @@ class Seat: 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() -- 2.34.1