fall
authorFrank DeMarco <frank.s.demarco@gmail.com>
Fri, 25 Apr 2014 22:12:47 +0000 (07:12 +0900)
committerFrank DeMarco <frank.s.demarco@gmail.com>
Fri, 25 Apr 2014 22:12:47 +0000 (07:12 +0900)
scale_sieve/ScaleSieve.py

index 7f7f5d4..7b8f086 100644 (file)
@@ -1,3 +1,5 @@
+from random import randint
+
 from pygame import Surface, PixelArray
 
 from scale_sieve.pgfw.Game import Game
@@ -14,9 +16,11 @@ class ScaleSieve(Game):
     def set_children(self):
         Game.set_children(self)
         self.sieve = Sieve(self)
+        self.triangles = Triangles(self)
 
     def update(self):
         self.display.screen.blit(self.background, (0, 0))
+        self.triangles.update()
         self.sieve.update()
 
 
@@ -92,9 +96,13 @@ class Sieve(Strip):
         bar_locations = []
         x = 0
         nodeset = self.get_game().interpolator.get_nodeset("scale")
+        bar_w = 3
+        self.gaps = gaps = []
         while x < nodeset[-1].x:
             bar_locations.append(x)
-            x += nodeset.get_y(x, natural=True)
+            step = nodeset.get_y(x, natural=True)
+            gaps.append(step - bar_w)
+            x += step
         surface = Surface((x, 30))
         transparent_color = (255, 0, 255)
         surface.fill(transparent_color)
@@ -103,7 +111,7 @@ class Sieve(Strip):
         colors = (0, 255, 0), (153, 0, 204)
         for x in bar_locations:
             for ii, frame in enumerate(frames):
-                frame.fill(colors[ii], (x, 0, 3, surface.get_height()))
+                frame.fill(colors[ii], (x, 0, bar_w, surface.get_height()))
                 frame.fill(colors[ii - 1], (x + 1, 1, 1,
                                             surface.get_height() - 2))
         for frame in frames:
@@ -146,3 +154,30 @@ class Triangles(GameChild, list):
 
     def __init__(self, parent):
         GameChild.__init__(self, parent)
+        list.__init__(self, [])
+        self.set_next_gap()
+
+    def set_next_gap(self):
+        self.next_gap = randint(30, 56)
+
+    def update(self):
+        if not self or self[-1].location.top > self.next_gap:
+            self.append(Triangle(self))
+            self.set_next_gap()
+        if self[0].location.collidelist(self.parent.sieve.locations) != -1:
+            self.remove(self[0])
+        for triangle in self:
+            triangle.update()
+
+
+class Triangle(Sprite):
+
+    def __init__(self, parent):
+        Sprite.__init__(self, parent)
+        surface = Surface((100, 20))
+        surface.fill((69, 178, 220))
+        self.add_frame(surface)
+
+    def update(self):
+        self.move(dy=8)
+        Sprite.update(self)