Serum assembly.
authorSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 22:42:41 +0000 (00:42 +0200)
committerSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 22:42:41 +0000 (00:42 +0200)
koperkapel/serums.py

index 951d002490bc7fbb14b9273fcdd1338fd27354d9..c2a52bba6ff0e10525597d2b1a1760108ef95036 100644 (file)
@@ -1,8 +1,17 @@
 """ Tools for creating serum actors. """
 
+from pgzero.loaders import images
+from pygame.constants import BLEND_RGBA_MULT
+from .actors.surf import SurfActor
 
 SERUMS = ["smart", "fast", "strong"]
 
+SERUM_TILENAME_MAP = {
+    "smart": "intelligence",
+    "fast": "speed",
+    "strong": "strength",
+}
+
 SERUM_OVERLAY_COLORS = {
     "smart": (0, 0, 255, 255),  # blue
     "fast": (0, 255, 0, 255),  # green
@@ -16,3 +25,22 @@ def roach_serum_color(roach):
         if getattr(roach, serum_name):
             return SERUM_OVERLAY_COLORS[serum_name]
     return SERUM_OVERLAY_COLORS["none"]
+
+
+class SerumFactory:
+    def __init__(self, suffix):
+        self.suffix = suffix
+
+    def assemble(self, name):
+        assert name in SERUMS
+        puddle = images.load("serum%s/serum" % (self.suffix,))
+        serum_icon = images.load("serum%s/%s" % (
+            self.suffix, SERUM_TILENAME_MAP[name],))
+        frame = puddle.copy()
+        frame.fill(SERUM_OVERLAY_COLORS[name], None, BLEND_RGBA_MULT)
+        frame.blit(serum_icon, (0, 0))
+        return SurfActor(frame)
+
+
+default_serums = SerumFactory("")
+big_serums = SerumFactory("_big")