Source

pygamegsoc12 / alchemymadness / tubes.py

Full commit
from pygame.locals import Rect

import layout
import resources
from sprite import MaskedSprite, Node

class Tubes(Node):
    def __init__(self, *groups):
        super(Tubes, self).__init__()
        for i, r in enumerate(layout.Main.tube_rects):
            self.add_node(Tube(i, r, *groups))
        for t in self.children:
            print t.rect, t.mask_rect

    def set_colors(self, colors):
        for t in self.children:
            t.set_color(colors[t.id])

class Tube(Node, MaskedSprite):
    def __init__(self, tid, rect, *groups):
        super(Tube, self).__init__((255,255,255), *groups)
        self.rect = rect
        self.mask_rect = Rect((0, self.rect.h), self.rect.size)
        self.id = tid
        self.t_image = resources.background_mask.subsurface(self.rect)
        self.dirty = 1

    def set_color(self, color):
        self.mask_rect = Rect((0, self.rect.h), self.rect.size)
        self.mix_color(color, 1.)
        self.move_mask(Rect((0, 0), self.rect.size))