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),
13 "brown": (170, 68, 0, 255),
17 class RoachActor(SurfActor):
18 def __init__(self, frames):
20 self._frame = random.randint(0, len(frames) - 1)
23 each_tick(self.update)
24 super().__init__(surf=frames[self._frame])
28 while self._dt > self._cycle_dt:
29 self._dt -= self._cycle_dt
31 self._frame %= len(self._frames)
32 self.surf = self._frames[self._frame]
37 def __init__(self, suffix, frames=4):
41 def roach_color(self, roach):
43 return ROACH_COLORS["blue"]
45 return ROACH_COLORS["green"]
47 return ROACH_COLORS["purple"]
48 return ROACH_COLORS["brown"]
50 def assemble_frame(self, i, color, roach_data):
51 roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
52 eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
54 roach.fill(color, None, BLEND_RGBA_MULT)
55 roach.blit(eyes, (0, 0))
58 def assemble(self, roach_data):
59 color = self.roach_color(roach_data)
61 self.assemble_frame(i, color, roach_data)
62 for i in range(self.frames)]
63 return RoachActor(frames)
66 default_roaches = RoachFactory("")
67 t32_roaches = RoachFactory("_32")
68 t21_roaches = RoachFactory("_21")
69 big_roaches = RoachFactory("_big")