1 """ Tools for creating roach actors. """
4 from pgzero.clock import each_tick
5 from pgzero.loaders import images
6 from .actors.surf import SurfActor
9 class RoachActor(SurfActor):
10 def __init__(self, frames):
12 self._frame = random.randint(0, len(frames) - 1)
15 each_tick(self.update)
16 super().__init__(surf=frames[self._frame])
20 while self._dt > self._cycle_dt:
21 self._dt -= self._cycle_dt
23 self._frame %= len(self._frames)
24 self.surf = self._frames[self._frame]
29 def __init__(self, suffix, frames=4):
33 def assemble_frame(self, i, roach_data):
34 roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
35 eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
36 roach.blit(eyes, (0, 0))
39 def assemble(self, roach_data):
41 self.assemble_frame(i, roach_data) for i in range(self.frames)]
42 return RoachActor(frames)
45 default_roaches = RoachFactory("")
46 t32_roaches = RoachFactory("_32")
47 t21_roaches = RoachFactory("_21")
48 big_roaches = RoachFactory("_big")