Source

pygamegsoc12 / alchemymadness / potion.py

"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… c523ef9 







"Sam...@sambull.… a352039 

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


"Sam...@sambull.… 47c1374 

Szymon Wróblewsk… c523ef9 
"Sam...@sambull.… 28aadf7 
"Sam...@sambull.… 47c1374 
Szymon Wróblewsk… 8d74cfa 
Szymon Wróblewsk… bd25010 


"Sam...@sambull.… 47c1374 
"Sam...@sambull.… 28aadf7 

Szymon Wróblewsk… 2661df1 
"Sam...@sambull.… 28aadf7 


Szymon Wróblewsk… bd25010 

"Sam...@sambull.… 28aadf7 





Szymon Wróblewsk… bd25010 

"Sam...@sambull.… 28aadf7 
"""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.

        """
        self.chems += 1
        n = ((self.chems-1) / float(self.chems))
        self.mix_color(col, n)
#        self.target_col = (self.color[0] * n, self.color[1] * n, self.color[2] * n)
#        self.target_col = (self.target_col[0] + col[0]/float(self.chems),
#                           self.target_col[1] + col[1]/float(self.chems),
#                           self.target_col[2] + col[2]/float(self.chems))
#        self.diff_col = ((self.target_col[0] - self.color[0]),
#                         (self.target_col[1] - self.color[1]),
#                         (self.target_col[2] - self.color[2]))
        # Update position
        n = self.chems / float(self.max_chems)
        self.target_y = self.mask_rect.h*(1-n)

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

    def update(self, time):
        super(Potion, self).update(time)
        # Move rect smoothly
        if self.target_y is not None:
            self.dirty = 1
            self.mask_rect.y -= 5*(time/1000.)
            if self.mask_rect.y < self.target_y:
                self.mask_rect.y = self.target_y
                self.target_y = None
        # Lerp colours
        if self.target_col is not None:
            self.changed = True
            diff = (self.diff_col[0] * (time/500.),
                    self.diff_col[1] * (time/500.),
                    self.diff_col[2] * (time/500.))
            col = [self.color[0] + diff[0], self.color[1] + diff[1],
                   self.color[2] + diff[2]]
            for i in range(3):
                if diff[i] > 0:
                    col[i] = min(col[i], self.target_col[i])
                else:
                    col[i] = max(col[i], self.target_col[i])

            self.color = tuple(col)
            if self.color == self.target_col:
                self.target_col = None
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.