self.surf = self._frames[self._frame]
+class WorldRoach(object):
+ """A roach proxy with no properties for display on the game level."""
+
+ def __init__(self):
+ self.smart = False
+ self.strong = False
+ self.fast = False
+
+
class RoachFactory:
def __init__(self, suffix, frames=4):
t32_roaches = RoachFactory("_32")
t21_roaches = RoachFactory("_21")
big_roaches = RoachFactory("_big")
+roaches_quartet = RoachFactory("_quartet")
+roaches_nonet = RoachFactory("_nonet")
from ..loaders.levelloader import levels
from .base import Scene, ChangeSceneEvent, MoveViewportEvent
from ..constants import TILE_SIZE, WIDTH, HEIGHT
-from ..roaches import default_roaches
+from ..vehicles.base import Vehicle
class BaseLevelScene(Scene):
def enter(self, world):
super().enter(world)
self._roaches = self.actors.add_layer("roaches", level=10)
+ self._vehicle = Vehicle.current(world)
self._mode = 'walk'
- return self._init_roaches(world.roaches)
+ self._angle = 0
+ return self._init_roaches(world)
- def _init_roaches(self, roaches):
- for roach in roaches:
- roach_actor = self._roaches.add(default_roaches.assemble(roach))
- roach_actor.anchor = (0, 0)
- roach_actor.pos = (WIDTH // 2, HEIGHT // 2)
+ def _init_roaches(self, world):
x, y = self._level.start_pos
- self._set_pos(x, y)
self._level_layer = 'floor'
+ self._avatar = self._vehicle.get_avatar(world)
+ self._set_pos(x, y)
+ self._avatar.pos = (WIDTH // 2, HEIGHT // 2)
+ self._roaches.add(self._avatar)
# Fix viewport offset
return [MoveViewportEvent((x * TILE_SIZE - WIDTH // 2, y * TILE_SIZE - HEIGHT // 2))]
return self._level.can_crawl(x, y, self._level_layer)
def _set_angle(self, angle):
- for roach in self._roaches:
- roach.angle = angle
+ self._angle = angle
+ self._avatar.angle = angle
+
+ def update(self, world, engine, dt):
+ if self._vehicle.changed():
+ self._roaches.remove(self._avatar)
+ self._avatar = self._vehicle.get_avatar(world)
+ self._avatar.pos = (WIDTH // 2, HEIGHT // 2)
+ self._roaches.add(self._avatar)
+ self._avatar.set_angle(self._angle)
+ super().update(world, engine, dt)
def on_key_down(self, key, mod, unicode):
offset = None
elif key == keys.V:
# Leave vehicle
print('Vehicle key pressed')
-
if offset:
return [MoveViewportEvent(offset)]
return super(GameLevelScene, self).on_key_down(key, mod, unicode)
import math
from .base import Vehicle, Seat
-
+from ..roaches import default_roaches, roaches_quartet, roaches_nonet, WorldRoach
class Walking(Vehicle):
pos=(math.sin(i * d_theta), math.cos(i * d_theta)))
for i in range(n_seats)
]
+
+ def get_avatar(self, world):
+ num_roaches = len(world.roaches)
+ roach = WorldRoach()
+ if num_roaches == 1:
+ # Return a single large roach
+ avatar = default_roaches.assemble(roach)
+ avatar.anchor = (0, 0)
+ elif num_roaches < 6:
+ avatar = roaches_quartet.assemble(roach)
+ avatar.anchor = (-16, 0)
+ else:
+ avatar = roaches_nonet.assemble(roach)
+ return avatar
+
+ def changed(self):
+ return False