1 """ Tools for creating roach actors. """
3 from pgzero.loaders import images
4 from pygame.constants import BLEND_RGBA_MULT
5 from .actors.animsurf import AnimatedSurfActor
6 from .serums import roach_serum_color
35 def roach_by_name(world, roach_name):
36 roaches = [r for r in world.roaches if r.name == roach_name]
42 def next_roach_name(world):
43 roach_names = [x['name'] for x in world.roaches]
45 if cand not in roach_names:
49 def build_roach(world, name=None, health=5, **kw):
51 name = next_roach_name(world)
62 class WorldRoach(object):
63 """A roach proxy with no properties for display on the game level."""
73 def __init__(self, suffix, frames=4):
77 def assemble_frame(self, i, color, roach_data):
78 roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
79 eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
81 frame.fill(color, None, BLEND_RGBA_MULT)
82 frame.blit(eyes, (0, 0))
85 def assemble(self, roach_data):
86 color = roach_serum_color(roach_data)
88 self.assemble_frame(i, color, roach_data)
89 for i in range(self.frames)]
90 return AnimatedSurfActor(frames)
93 default_roaches = RoachFactory("")
94 t32_roaches = RoachFactory("_32")
95 t21_roaches = RoachFactory("_21")
96 big_roaches = RoachFactory("_big")
97 roaches_quartet = RoachFactory("_quartet")
98 roaches_nonet = RoachFactory("_nonet")