1 """ Tools for creating roach actors. """
4 from pgzero.clock import each_tick
5 from pgzero.loaders import images
6 from pygame.constants import BLEND_RGBA_MULT
7 from .actors.orientatedsurf import OrientatedSurfActor
8 from .serums import roach_serum_color
11 def roach_by_name(world, roach_name):
12 roaches = [r for r in world.roaches if r.name == roach_name]
18 class RoachActor(OrientatedSurfActor):
19 def __init__(self, frames):
21 self._frame = random.randint(0, len(frames) - 1)
24 each_tick(self.update)
25 super().__init__(surf=frames[self._frame], angle=0)
29 while self._dt > self._cycle_dt:
30 self._dt -= self._cycle_dt
32 self._frame %= len(self._frames)
33 self.surf = self._frames[self._frame]
36 class WorldRoach(object):
37 """A roach proxy with no properties for display on the game level."""
47 def __init__(self, suffix, frames=4):
51 def assemble_frame(self, i, color, roach_data):
52 roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
53 eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
55 frame.fill(color, None, BLEND_RGBA_MULT)
56 frame.blit(eyes, (0, 0))
59 def assemble(self, roach_data):
60 color = roach_serum_color(roach_data)
62 self.assemble_frame(i, color, roach_data)
63 for i in range(self.frames)]
64 return RoachActor(frames)
67 default_roaches = RoachFactory("")
68 t32_roaches = RoachFactory("_32")
69 t21_roaches = RoachFactory("_21")
70 big_roaches = RoachFactory("_big")
71 roaches_quartet = RoachFactory("_quartet")
72 roaches_nonet = RoachFactory("_nonet")