Working HUD.
[koperkapel.git] / koperkapel / serums.py
1 """ Tools for creating serum actors. """
2
3 import random
4 from pgzero.loaders import images
5 from pygame.constants import BLEND_RGBA_MULT
6 from pygame.transform import rotate
7 from .actors.surf import SurfActor
8 from .util import safepath
9
10 SERUMS = ["smart", "fast", "strong"]
11
12 SERUM_TILENAME_MAP = {
13     "smart": "intelligence",
14     "fast": "speed",
15     "strong": "strength",
16 }
17
18 SERUM_OVERLAY_COLORS = {
19     "smart": (0, 0, 255, 255),  # blue
20     "fast": (0, 255, 0, 255),  # green
21     "strong": (255, 0, 255, 255),  # purple
22     "health": (255, 0, 0, 255),  # red
23     "none": (170, 68, 0, 255),  # brown
24 }
25
26
27 def roach_serum_color(roach):
28     for serum_name in SERUMS:
29         if getattr(roach, serum_name):
30             return SERUM_OVERLAY_COLORS[serum_name]
31     return SERUM_OVERLAY_COLORS["none"]
32
33
34 def roach_is_serumless(roach):
35     for serum_name in SERUMS:
36         if getattr(roach, serum_name):
37             return False
38     return True
39
40
41 class SerumFactory:
42     def __init__(self, suffix):
43         self.suffix = suffix
44
45     def assemble_icon(self, name, color=None):
46         assert name in SERUMS
47         color = color or name
48         serum_icon = images.load(safepath("serum%s/%s") % (
49             self.suffix, SERUM_TILENAME_MAP[name],))
50         frame = serum_icon.copy()
51         frame.fill(SERUM_OVERLAY_COLORS[color], None, BLEND_RGBA_MULT)
52         return frame
53
54     def assemble(self, name):
55         assert name in SERUMS
56         puddle = images.load(safepath("serum%s/serum") % (self.suffix,))
57         puddle = rotate(puddle, 90 * random.randint(0, 3))
58         serum_icon = images.load(safepath("serum%s/%s") % (
59             self.suffix, SERUM_TILENAME_MAP[name],))
60         frame = puddle.copy()
61         frame.fill(SERUM_OVERLAY_COLORS[name], None, BLEND_RGBA_MULT)
62         frame.blit(serum_icon, (0, 0))
63         return SurfActor(frame)
64
65
66 default_serums = SerumFactory("")
67 big_serums = SerumFactory("_big")