Commits

Szymon Wróblewski committed c523ef9

MaskedSprite have color mixing animation (from Potion), added higher res images

  • Participants
  • Parent commits bd25010

Comments (0)

Files changed (10)

File alchemymadness/blocks.py

     def action_move_right(self):
         doit = True
         for b in self.grid_positions:
+
             b[0] += 1
             if b[0] >= self.parent.grid_size.w:
                 doit = False
 
         self.on_moved()
 
+    def change_color(self, color):
+        for b in self.sprite_group:
+            b.mix_color(color, 1)
+
 
 class Grid(object):
     """ Contains Blocks()

File alchemymadness/data/bg.png

Old
Old image
New
New image

File alchemymadness/data/bg_mask.png

Old
Old image
New
New image

File alchemymadness/data/block.png

Old
Old image
New
New image

File alchemymadness/data/block_.png

Added
New image

File alchemymadness/data/block_small.png

Added
New image

File alchemymadness/main.py

+from random import randint
 
 import pygame
 from pygame.locals import *
     # Initialise level
     pot = potion.Potion()
     pot.set_formula(3, 5, 3)
+    # TODO: change something so potion dont start filled with white fluid
     sprites = pygame.sprite.LayeredDirty(pot)
     sprites.clear(screen, resources.background)
 
                     blks.action_move_up()
                 if e.key == K_DOWN:
                     blks.action_move_down()
+                if e.key == K_c:
+                    blks.change_color((randint(0,255),randint(0,255),randint(0,255)))
 
                 # press keys 1-4 to control player 1-4.
                 if e.key in [K_1, K_2, K_3, K_4]:

File alchemymadness/potion.py

           groups to add sprite to
 
         """
-        super(Potion, self).__init__((0,0,0), *groups)
+        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)
 
         """
         self.chems += 1
         n = ((self.chems-1) / float(self.chems))
-        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]))
-
+        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)
         pass
 
     def update(self, time):
+        super(Potion, self).update(time)
         # Move rect smoothly
         if self.target_y is not None:
             self.dirty = 1

File alchemymadness/resources.py

     background = pygame.image.load(skelutil.data_dir("bg.png")).convert_alpha()
     background_mask = pygame.image.load(skelutil.data_dir("bg_mask.png")).convert_alpha()
     block = pygame.image.load(skelutil.data_dir("block.png")).convert_alpha()
-    sblock = pygame.transform.scale(block, (int(block.get_rect().w/2), int(block.get_rect().h/2)))
+    sblock = pygame.image.load(skelutil.data_dir("block_small.png")).convert_alpha()
+    #sblock = pygame.transform.scale(block, (int(block.get_rect().w/2), int(block.get_rect().h/2)))
     font = Font(skelutil.data_dir("The Alchemist.ttf"))
 
 class Font(object):

File alchemymadness/sprite.py

     changed should be set to True whenever mask_rect is modified
     """
     rect = Rect(0,0,10,10)
-    changed = False # True if sprite image need to be colored
+    changed = False
     fill_flags = pygame.locals.BLEND_RGBA_MULT
+    target_col = None
+    target_rect = None
 
     def __init__(self, color, *groups):
         """
     def color(self, value):
         self._color = value
         self.changed = True
+        self.dirty = 1
+
+    def mix_color(self, color, ratio=0.5):
+        """Mix a color with specified ratio
+
+        col: tuple containing rgb colour
+        ratio: color mix ratio (1 - max new color)
+        """
+        self.target_col = tuple(self.color[i] * (1 - ratio) + color[i] * ratio for i in range(len(self.color)))
+        self.diff_col = tuple(self.target_col[i] - self.color[i] for i in range(len(self.color)))
+
+    def update(self, time):
+        """Update color and mask_rect"""
+        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