From: Simon Cross Date: Fri, 4 Mar 2016 19:21:05 +0000 (+0200) Subject: Place roach seats. X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=6cb552f903dce3e3bad9b3f3be829f0996422ae2;p=koperkapel.git Place roach seats. --- diff --git a/koperkapel/scenes/roaches.py b/koperkapel/scenes/roaches.py index 342f23c..cecd6ef 100644 --- a/koperkapel/scenes/roaches.py +++ b/koperkapel/scenes/roaches.py @@ -11,6 +11,8 @@ from .base import Scene, ChangeSceneEvent 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) @@ -28,6 +30,7 @@ class RoachesScene(Scene): 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() @@ -38,12 +41,15 @@ class RoachesScene(Scene): 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( diff --git a/koperkapel/vehicles/base.py b/koperkapel/vehicles/base.py index 27373a5..0909004 100644 --- a/koperkapel/vehicles/base.py +++ b/koperkapel/vehicles/base.py @@ -1,13 +1,15 @@ """ 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 = {} @@ -30,6 +32,7 @@ class Vehicle: 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. @@ -37,7 +40,8 @@ class Seat: 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) diff --git a/koperkapel/vehicles/walking.py b/koperkapel/vehicles/walking.py index f819892..adcdfc9 100644 --- a/koperkapel/vehicles/walking.py +++ b/koperkapel/vehicles/walking.py @@ -1,17 +1,19 @@ """ 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")