c844b5277c404c41c4448239d58daa564fecb570
[koperkapel.git] / koperkapel / roaches.py
1 """ Tools for creating roach actors. """
2
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
8
9 def roach_by_name(world, roach_name):
10     roaches = [r for r in world.roaches if r.name == roach_name]
11     if not roaches:
12         return None
13     return roaches[0]
14
15
16 class WorldRoach(object):
17     """A roach proxy with no properties for display on the game level."""
18
19     def __init__(self):
20         self.smart = False
21         self.strong = False
22         self.fast = False
23
24
25 class RoachFactory:
26
27     def __init__(self, suffix, frames=4):
28         self.suffix = suffix
29         self.frames = 4
30
31     def assemble_frame(self, i, color, roach_data):
32         roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
33         eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
34         frame = roach.copy()
35         frame.fill(color, None, BLEND_RGBA_MULT)
36         frame.blit(eyes, (0, 0))
37         return frame
38
39     def assemble(self, roach_data):
40         color = roach_serum_color(roach_data)
41         frames = [
42             self.assemble_frame(i, color, roach_data)
43             for i in range(self.frames)]
44         return AnimatedSurfActor(frames)
45
46
47 default_roaches = RoachFactory("")
48 t32_roaches = RoachFactory("_32")
49 t21_roaches = RoachFactory("_21")
50 big_roaches = RoachFactory("_big")
51 roaches_quartet = RoachFactory("_quartet")
52 roaches_nonet = RoachFactory("_nonet")