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.surf import SurfActor
8 from .serums import roach_serum_color
11 class RoachActor(SurfActor):
12 def __init__(self, frames):
14 self._frame = random.randint(0, len(frames) - 1)
17 each_tick(self.update)
18 super().__init__(surf=frames[self._frame])
22 while self._dt > self._cycle_dt:
23 self._dt -= self._cycle_dt
25 self._frame %= len(self._frames)
26 self.surf = self._frames[self._frame]
31 def __init__(self, suffix, frames=4):
35 def assemble_frame(self, i, color, roach_data):
36 roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
37 eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
39 frame.fill(color, None, BLEND_RGBA_MULT)
40 frame.blit(eyes, (0, 0))
43 def assemble(self, roach_data):
44 color = roach_serum_color(roach_data)
46 self.assemble_frame(i, color, roach_data)
47 for i in range(self.frames)]
48 return RoachActor(frames)
51 default_roaches = RoachFactory("")
52 t32_roaches = RoachFactory("_32")
53 t21_roaches = RoachFactory("_21")
54 big_roaches = RoachFactory("_big")