Give roaches more colours and fewer legs.
authorSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 20:45:27 +0000 (22:45 +0200)
committerSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 20:45:27 +0000 (22:45 +0200)
koperkapel/roaches.py

index 586b508a394be68fe10f01aed14b5869d9f67a17..904b8c7dfc9bdf927018cb200372080ce97ca635 100644 (file)
@@ -3,8 +3,15 @@
 import random
 from pgzero.clock import each_tick
 from pgzero.loaders import images
+from pygame.constants import BLEND_RGBA_MULT
 from .actors.surf import SurfActor
 
+ROACH_COLORS = {
+    "blue": (0, 0, 255, 255),
+    "green": (0, 255, 0, 255),
+    "purple": (255, 0, 255, 255),
+}
+
 
 class RoachActor(SurfActor):
     def __init__(self, frames):
@@ -30,15 +37,22 @@ class RoachFactory:
         self.suffix = suffix
         self.frames = 4
 
-    def assemble_frame(self, i, roach_data):
+    def roach_color(self, roach_data):
+        return random.choice(list(ROACH_COLORS.values()))
+
+    def assemble_frame(self, i, color, roach_data):
         roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
         eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
+        roach = roach.copy()
+        roach.fill(color, None, BLEND_RGBA_MULT)
         roach.blit(eyes, (0, 0))
         return roach
 
     def assemble(self, roach_data):
+        color = self.roach_color(roach_data)
         frames = [
-            self.assemble_frame(i, roach_data) for i in range(self.frames)]
+            self.assemble_frame(i, color, roach_data)
+            for i in range(self.frames)]
         return RoachActor(frames)