From 4d670fa2d34bf9e663a86a5b823470b255b9a173 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Fri, 4 Mar 2016 22:45:27 +0200 Subject: [PATCH] Give roaches more colours and fewer legs. --- koperkapel/roaches.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/koperkapel/roaches.py b/koperkapel/roaches.py index 586b508..904b8c7 100644 --- a/koperkapel/roaches.py +++ b/koperkapel/roaches.py @@ -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) -- 2.34.1