Selectable seats.
authorSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 12:12:37 +0000 (14:12 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 12:12:37 +0000 (14:12 +0200)
koperkapel/scenes/roach_management.py
koperkapel/vehicles/base.py

index 21fc37c0432e3f77a19f5830c4a2cee48f1f7e0c..7dc9c5eaff4952fb37e2e33f9cb57b415189ad6c 100644 (file)
@@ -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)
index f4506d602bfb520c0235ef9b4ac23f6cb475671a..9aff447f1fdbb0134635059671773734a9a6bd9a 100644 (file)
@@ -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()