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
7 from .util import safepath
36 def roach_by_name(world, roach_name):
37 roaches = [r for r in world.roaches if r.name == roach_name]
43 def next_roach_name(world):
44 roach_names = [x['name'] for x in world.roaches]
46 if cand not in roach_names:
50 def build_roach(world, name=None, health=5, **kw):
52 name = next_roach_name(world)
63 class WorldRoach(object):
64 """A roach proxy with no properties for display on the game level."""
74 def __init__(self, suffix, frames=4):
78 def assemble_frame(self, i, color, roach_data, weapon=None):
79 roach = images.load(safepath("roach%s/roach_%d") % (self.suffix, i + 1))
80 eyes = images.load(safepath("roach%s/eyes_%d") % (self.suffix, i + 1))
83 frame.fill(color, None, BLEND_RGBA_MULT)
85 frame = weapon.surf.copy()
87 roach.fill(color, None, BLEND_RGBA_MULT)
88 frame.blit(roach, (0, 0))
89 frame.blit(eyes, (0, 0))
92 def assemble(self, roach_data, color=None, weapon=None):
94 color = roach_serum_color(roach_data)
97 self.assemble_frame(i, color, roach_data, weapon)
98 for i in range(self.frames)]
99 return AnimatedSurfActor(frames)
102 default_roaches = RoachFactory("")
103 t32_roaches = RoachFactory("_32")
104 t21_roaches = RoachFactory("_21")
105 big_roaches = RoachFactory("_big")
106 roaches_quartet = RoachFactory("_quartet")
107 roaches_nonet = RoachFactory("_nonet")