Commits

Szymon Wróblewski committed 56eb69f

tubes works now (resolved overwriting Sprite add method in classes inheriting after Node)

Comments (0)

Files changed (4)

alchemymadness/layout.py

     potion_rect = Rect(372, 360, 130, 194)
     small_potion_rect = Rect(553, 454, 68, 100)
     spiral_rect = Rect(718, 255, 82, 280)
-    tube_rects = tuple(Rect(63 + i * 25, 447, 24, 76) for i in range(9))
+    tube_rects = tuple(Rect(63 + i * 25, 457, 24, 66) for i in range(9))
     input_rects = (
         Rect(300, 277, 56, 71),
         Rect(400, 236, 50, 40),

alchemymadness/main.py

     pot.set_formula(3, 5, 3)
     sprites = pygame.sprite.LayeredDirty(pot)
     tbs = tubes.Tubes(sprites)
-    tbs.set_colors(((255,0,0),(0,255,0),(0,0,255),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0)))
+    tbs.set_colors(((255,0,0),(0,255,0),(0,0,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255)))
     sprites.clear(screen, resources.background)
 
     grds = blocks.Grids(sprites)

alchemymadness/sprite.py

 class Node(object):
     def __init__(self, *args, **kwargs):
         super(Node, self).__init__(*args, **kwargs)
-        print self, args
         self._parent = None
         self._children = set() # unordered !!
 
     def children(self):
         return self._children
 
-    def add(self, node):
+    def add_node(self, node):
         node.parent = self
 
-    def discard(self, node):
+    def discard_node(self, node):
         node.parent = None
 
-
 class MaskedSprite(DirtySprite):
     """ Sprite with color
 

alchemymadness/tubes.py

+from pygame.locals import Rect
 
 import layout
 import resources
     def __init__(self, *groups):
         super(Tubes, self).__init__()
         for i, r in enumerate(layout.Main.tube_rects):
-            self.add(Tube(i, r, *groups))
+            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.mix_color(colors[t.id], 1.)
+            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.rect = rect
         self.t_image = resources.background_mask.subsurface(self.rect)
         self.dirty = 1
 
-    def update(self, time):
-        super(Tube, self).update(time)
-        print 't update'
+    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))