Very crudely hack vehicles into the level
[koperkapel.git] / koperkapel / roaches.py
1 """ Tools for creating roach actors. """
2
3 import random
4 from pgzero.clock import each_tick
5 from pgzero.loaders import images
6 from pygame.constants import BLEND_RGBA_MULT
7 from .actors.orientatedsurf import OrientatedSurfActor
8 from .serums import roach_serum_color
9
10
11 class RoachActor(OrientatedSurfActor):
12     def __init__(self, frames):
13         self._frames = frames
14         self._frame = random.randint(0, len(frames) - 1)
15         self._dt = 0
16         self._cycle_dt = 0.2
17         each_tick(self.update)
18         super().__init__(surf=frames[self._frame], angle=0)
19
20     def update(self, dt):
21         self._dt += dt
22         while self._dt > self._cycle_dt:
23             self._dt -= self._cycle_dt
24             self._frame += 1
25             self._frame %= len(self._frames)
26         self.surf = self._frames[self._frame]
27
28
29 class WorldRoach(object):
30     """A roach proxy with no properties for display on the game level."""
31
32     def __init__(self):
33         self.smart = False
34         self.strong = False
35         self.fast = False
36
37
38 class RoachFactory:
39
40     def __init__(self, suffix, frames=4):
41         self.suffix = suffix
42         self.frames = 4
43
44     def assemble_frame(self, i, color, roach_data):
45         roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
46         eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
47         frame = roach.copy()
48         frame.fill(color, None, BLEND_RGBA_MULT)
49         frame.blit(eyes, (0, 0))
50         return frame
51
52     def assemble(self, roach_data):
53         color = roach_serum_color(roach_data)
54         frames = [
55             self.assemble_frame(i, color, roach_data)
56             for i in range(self.frames)]
57         return RoachActor(frames)
58
59
60 default_roaches = RoachFactory("")
61 t32_roaches = RoachFactory("_32")
62 t21_roaches = RoachFactory("_21")
63 big_roaches = RoachFactory("_big")
64 roaches_quartet = RoachFactory("_quartet")
65 roaches_nonet = RoachFactory("_nonet")