Show weapons when walking.
[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 NAMES = [
9     "roupert",
10     "roachel",
11     "roeginald",
12     "roichard",
13     "rory",
14     "roalph",
15     "roabia",
16     "roafi",
17     "roaman",
18     "roemus",
19     "roadley",
20     "roanaell",
21     "roashwan",
22     "roashid",
23     "roaphael",
24     "roenfield",
25     "roani",
26     "roaya",
27     "roaza",
28     "robekka",
29     "rogan",
30     "roiana",
31     "roberta",
32 ]
33
34
35 def roach_by_name(world, roach_name):
36     roaches = [r for r in world.roaches if r.name == roach_name]
37     if not roaches:
38         return None
39     return roaches[0]
40
41
42 def next_roach_name(world):
43     roach_names = [x['name'] for x in world.roaches]
44     for cand in NAMES:
45         if cand not in roach_names:
46             return cand
47
48
49 def build_roach(world, name=None, health=5, **kw):
50     if name is None:
51         name = next_roach_name(world)
52     if name is None:
53         return
54     roach = {
55         "name": name,
56         "health": health,
57     }
58     roach.update(kw)
59     return roach
60
61
62 class WorldRoach(object):
63     """A roach proxy with no properties for display on the game level."""
64
65     def __init__(self):
66         self.smart = False
67         self.strong = False
68         self.fast = False
69
70
71 class RoachFactory:
72
73     def __init__(self, suffix, frames=4):
74         self.suffix = suffix
75         self.frames = 4
76
77     def assemble_frame(self, i, color, roach_data, weapon=None):
78         roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
79         eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
80         if weapon is None:
81             frame = roach.copy()
82             frame.fill(color, None, BLEND_RGBA_MULT)
83         else:
84             frame = weapon.surf.copy()
85             roach = roach.copy()
86             roach.fill(color, None, BLEND_RGBA_MULT)
87             frame.blit(roach, (0, 0))
88         frame.blit(eyes, (0, 0))
89         return frame
90
91     def assemble(self, roach_data, weapon=None):
92         color = roach_serum_color(roach_data)
93         frames = []
94         frames = [
95             self.assemble_frame(i, color, roach_data, weapon)
96             for i in range(self.frames)]
97         return AnimatedSurfActor(frames)
98
99
100 default_roaches = RoachFactory("")
101 t32_roaches = RoachFactory("_32")
102 t21_roaches = RoachFactory("_21")
103 big_roaches = RoachFactory("_big")
104 roaches_quartet = RoachFactory("_quartet")
105 roaches_nonet = RoachFactory("_nonet")