Source

pygamegsoc12 / alchemymadness / potion.py

Full commit
"Sam...@sambull.… b088e0d 

Szymon Wróblewsk… 8d74cfa 
"Sam...@sambull.… 9b5db54 
"Sam...@sambull.… b088e0d 
Szymon Wróblewsk… 8d74cfa 
Szymon Wróblewsk… 57153a0 
Szymon Wróblewsk… bd25010 
Szymon Wróblewsk… 8d74cfa 
Szymon Wróblewsk… bd25010 
"Sam...@sambull.… 9b5db54 

"Sam...@sambull.… 28aadf7 
"Sam...@sambull.… 9b5db54 
Szymon Wróblewsk… 57153a0 
"Sam...@sambull.… 47c1374 
Szymon Wróblewsk… 2661df1 

Szymon Wróblewsk… 8d74cfa 
Szymon Wróblewsk… 2661df1 






Szymon Wróblewsk… c523ef9 
Szymon Wróblewsk… bd25010 

"Sam...@sambull.… b088e0d 
"Sam...@sambull.… 9b5db54 




"Sam...@sambull.… a352039 
Szymon Wróblewsk… bd25010 
"Sam...@sambull.… b088e0d 
"Sam...@sambull.… 9b5db54 


"Sam...@sambull.… b088e0d 
"Sam...@sambull.… 9b5db54 



Szymon Wróblewsk… 4525fc3 






"Sam...@sambull.… a352039 
"Sam...@sambull.… 9b5db54 

"""Mixing potion"""

import pygame
from pygame.locals import Rect

import resources
import layout
from sprite import MaskedSprite

class Potion(MaskedSprite):
    chems = 0  # Chem count
    formula = (0,0,0)  # Target formula
    target_col = None
    max_chems = 0  # Target number of chems
    rect = layout.Main.potion_rect
    target_y = None
    changed = False

    def __init__(self, *groups):
        """
        Init potion sprite.

        Args:
          groups to add sprite to

        """
        super(Potion, self).__init__((255,255,255), *groups)
        self.t_image = resources.background_mask.subsurface(self.rect)
        self.mask_rect = Rect((0, self.rect.h), self.rect.size)

    def set_formula(self, r=0, g=0, b=0):
        """Set the target formula for the level."""
        self.chems = 0
        self.formula = (r, g, b)
        self.max_chems = sum(self.formula)
        # Offset the rect to be at bottom of potion
        self.mask_rect.y = self.mask_rect.h

    def add_color(self, col):
        """
        Add a colour from a player's board.

        Args:
          col: tuple containing rgb colour.

        """
        if self.chems < self.max_chems:
            self.chems += 1
            self.mix_color(col, 1/float(self.chems))
            r = self.mask_rect.copy()
            n = self.chems / float(self.max_chems)
            r.y = self.mask_rect.h*(1-n)
            self.move_mask(r)

    def get_score(self):
        """Returns a score based on accuracy of the formula."""
        pass