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
10 "blue": (0, 0, 255, 255),
11 "green": (0, 255, 0, 255),
12 "purple": (255, 0, 255, 255),
16 class RoachActor(SurfActor):
17 def __init__(self, frames):
19 self._frame = random.randint(0, len(frames) - 1)
22 each_tick(self.update)
23 super().__init__(surf=frames[self._frame])
27 while self._dt > self._cycle_dt:
28 self._dt -= self._cycle_dt
30 self._frame %= len(self._frames)
31 self.surf = self._frames[self._frame]
36 def __init__(self, suffix, frames=4):
40 def roach_color(self, roach_data):
41 return random.choice(list(ROACH_COLORS.values()))
43 def assemble_frame(self, i, color, roach_data):
44 roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
45 eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
47 roach.fill(color, None, BLEND_RGBA_MULT)
48 roach.blit(eyes, (0, 0))
51 def assemble(self, roach_data):
52 color = self.roach_color(roach_data)
54 self.assemble_frame(i, color, roach_data)
55 for i in range(self.frames)]
56 return RoachActor(frames)
59 default_roaches = RoachFactory("")
60 t32_roaches = RoachFactory("_32")
61 t21_roaches = RoachFactory("_21")
62 big_roaches = RoachFactory("_big")