TOOLBAR_LEFT_X = WIDTH * 3 // 4
TOOLBAR_TOP_Y = 0
TOOLBAR_MID_Y = HEIGHT * 1 // 2
+VEHICLE_MID_X = WIDTH * 3 // 8
+VEHICLE_MID_Y = HEIGHT * 1 // 2
BUTTON_INSET = (20, 20)
self._roach_actors = {}
self._roaches = self.actors.add_layer("roaches", level=10)
self._pads = self.actors.add_layer("pads", level=5)
+ self._seats = self.actors.add_layer("seats", level=5)
self._buttons = self.actors.add_layer("buttons", level=6)
self._init_pads()
self._init_buttons()
self._init_seats()
def _init_bg(self):
- self.actors.default.add(Actor("vehicles/walking/background"))
self.actors.default.add(self._vehicle.background)
def _init_seats(self):
- print("Seats:")
- print([seat.pos for seat in self._vehicle.seats])
+ vrad = self._vehicle.approximate_radius
+ for seat in self._vehicle.seats:
+ seat_actor = self._seats.add(seat.actor)
+ seat_actor.pos = (
+ seat.pos[0] * vrad + VEHICLE_MID_X,
+ seat.pos[1] * vrad + VEHICLE_MID_Y)
def _init_pads(self):
self._roach_pad = self._pads.add(
""" Base class for vehicles. """
+from pgzero.actor import Actor
+
class Vehicle:
""" Vehicle base class.
A vehicle should have the following attributes:
- * seats -- list of roach seats.
* background -- actor representing background for management scene
+ * seats -- list of roach seats.
"""
vehicle_types = {}
class Seat:
""" A space in a vehicle for a roach.
+ * background -- actor representing the seat.
* pos -- (x, y) position of the seat relative to the centre of the vehicle.
x and y may be numbers from approximately -1.0 to 1.0. They will be
multiplied by the approximate_radius of the vehicle.
seat
"""
- def __init__(self, pos, allowed=None):
+ def __init__(self, actor, pos, allowed=None):
+ self.actor = actor
self.pos = pos
self.allowed = allowed or (lambda roach: True)
""" A vehicle to represent roaches on foot. """
import math
+from pgzero.actor import Actor
from .base import Vehicle, Seat
-from ..actors.buttons import TextButton
class Walking(Vehicle):
def __init__(self):
+ self.background = Actor("vehicles/walking/background")
n_seats = 6
d_theta = 2 * math.pi / n_seats
self.seats = [
- Seat(pos=(math.sin(i * d_theta), math.cos(i * d_theta)))
+ Seat(
+ actor=Actor("vehicles/walking/seat"),
+ pos=(math.sin(i * d_theta), math.cos(i * d_theta)))
for i in range(n_seats)
]
- self.background = TextButton("Walking Background")