""" Base class for vehicles. """
+import math
from itertools import chain, islice, repeat
from pygame.constants import BLEND_RGBA_MULT
from pgzero.actor import Actor
from pgzero.loaders import images
from ..actors.orientatedsurf import OrientatedSurfActor
+from ..actors.animsurf import AnimatedSurfActor
class Vehicle:
return None
return roach_seating[seat_pos]
+ def changed(self):
+ return False # TODO: remove this
+
_vehicle_types = {}
@classmethod
@classmethod
def register_all(cls):
from .walking import Walking
+ from .quadcopter import Quadcopter
+ from .robot import Robot
+ from .roomba import Roomba
cls.register(Walking)
+ cls.register(Quadcopter)
+ cls.register(Robot)
+ cls.register(Roomba)
+
+ def _avatar_frame(self, i, suffix="_tiles"):
+ vehicle = images.load("vehicle%s/%s_%d" % (
+ suffix, self.vehicle_type, i + 1))
+ frame = vehicle.copy()
+ return frame
def get_avatar(self, world):
- raise NotImplementedError("Vehicles should know how to create their own avatars.")
+ frames = [self._avatar_frame(i) for i in range(4)]
+ return AnimatedSurfActor(frames)
class Seat:
self.surf = self._selected_seat if value else self._seat
+def circle_of_seats(n_seats, **kw):
+ d_theta = 2 * math.pi / n_seats
+ return [
+ Seat(pos=(math.sin(i * d_theta), math.cos(i * d_theta)), **kw)
+ for i in range(n_seats)]
+
+
Vehicle.register_all()
""" A vehicle to represent roaches on foot. """
-import math
-from .base import Vehicle, Seat
-from ..roaches import default_roaches, roaches_quartet, roaches_nonet, WorldRoach
+from .base import Vehicle, circle_of_seats
+from ..roaches import (
+ default_roaches, roaches_quartet, roaches_nonet, WorldRoach)
+
class Walking(Vehicle):
vehicle_type = "walking"
def init_seats(self):
- n_seats = 6
- d_theta = 2 * math.pi / n_seats
- return [
- Seat(
- vehicle=self,
- pos=(math.sin(i * d_theta), math.cos(i * d_theta)))
- for i in range(n_seats)
- ]
+ return circle_of_seats(6, vehicle=self)
def get_avatar(self, world):
num_roaches = len(world.roaches)
avatar = roaches_nonet.assemble(roach)
avatar.anchor = (0, 0)
return avatar
-
- def changed(self):
- return False