vshift
authorFrank DeMarco <frank.s.demarco@gmail.com>
Sat, 26 Apr 2014 05:06:45 +0000 (14:06 +0900)
committerFrank DeMarco <frank.s.demarco@gmail.com>
Sat, 26 Apr 2014 05:06:45 +0000 (14:06 +0900)
scale_sieve/ScaleSieve.py

index e5eb8c3..f52ae0f 100644 (file)
@@ -17,6 +17,7 @@ class ScaleSieve(Game):
 
     def set_children(self):
         Game.set_children(self)
+        self.acid = Acid(self)
         self.sieve = Sieve(self)
         self.triangles = Triangles(self)
 
@@ -34,8 +35,7 @@ class Strip(Sprite):
         Sprite.__init__(self, parent)
         self.display_surface = self.get_display_surface()
         self.delegate = self.get_game().delegate
-        self.shifts = Shift(self, 1), Shift(self, -1)
-        self.shift_nodeset = self.get_game().interpolator.get_nodeset("shift")
+        self.hshifts = Shift(self, -1, "shift-2"), Shift(self, 1, "shift-2")
         self.add_frames()
         self.subscribe(self.respond)
 
@@ -45,33 +45,27 @@ class Strip(Sprite):
     def respond(self, event):
         compare = self.delegate.compare
         if compare(event, "left") or compare(event, "left", True):
-            self.shifts[self.LEFT].active = not event.cancel
+            self.hshifts[self.LEFT].active = not event.cancel
         elif compare(event, "right") or compare(event, "right", True):
-            self.shifts[self.RIGHT].active = not event.cancel
+            self.hshifts[self.RIGHT].active = not event.cancel
 
     def update(self):
-        for shift in self.shifts:
+        for shift in self.hshifts:
             shift.update()
             if shift.time:
-                self.move(shift.get_dx())
-        # if self.location.left > 0:
-        #     self.location.left = 0
-        #     self.shifts[self.LEFT].time = 0
-        # elif self.location.right < self.display_surface.get_width():
-        #     self.location.right = self.display_surface.get_width()
-        #     self.shifts[self.RIGHT].time = 0
+                self.move(shift.get_change())
         Sprite.update(self)
 
 
 class Shift(GameChild):
 
-    def __init__(self, parent, direction):
+    def __init__(self, parent, direction, nodeset):
         GameChild.__init__(self, parent)
         self.direction = direction
         self.active = False
         self.time = 0
         self.timer = self.get_game().time_filter
-        self.nodeset = self.get_game().interpolator.get_nodeset("shift-2")
+        self.nodeset = self.get_game().interpolator.get_nodeset(nodeset)
 
     def update(self):
         least, greatest = self.nodeset[0].x, self.nodeset[-1].x
@@ -82,15 +76,19 @@ class Shift(GameChild):
             self.time = max(self.time - self.timer.get_last_frame_duration(),
                             least)
 
-    def get_dx(self):
+    def get_change(self):
         return self.nodeset.get_y(self.time) * self.direction
 
 
 class Sieve(Strip):
 
+    UP, DOWN = range(2)
+
     def __init__(self, parent):
         Strip.__init__(self, parent)
+        self.delegate = self.get_game().delegate
         self.location.center = self.display_surface.get_rect().center
+        self.vshifts = Shift(self, -1, "shift"), Shift(self, 1, "shift")
         self.electric = Electric(self)
         self.add_location(offset=(self.location.w, 0))
 
@@ -118,12 +116,33 @@ class Sieve(Strip):
         for frame in frames:
             self.add_frame(frame)
 
+    def respond(self, event):
+        Strip.respond(self, event)
+        compare = self.delegate.compare
+        if compare(event, "up") or compare(event, "up", True):
+            self.vshifts[self.UP].active = not event.cancel
+        elif compare(event, "down") or compare(event, "down", True):
+            self.vshifts[self.DOWN].active = not event.cancel
+
     def update(self):
-        if self.location.left > 0:
-            self.move(-self.location.w)
-        if self.locations[1].right < self.display_surface.get_width():
+        if self.location.right < 0:
             self.move(self.location.w)
-        self.electric.location.centery = self.location.centery
+        if self.locations[1].left > self.display_surface.get_width():
+            self.move(-self.location.w)
+        for shift in self.vshifts:
+            shift.update()
+            if shift.time:
+                self.move(dy=shift.get_change())
+        acid = self.parent.acid
+        if self.location.top < acid.ry[0]:
+            self.vshifts[self.UP].time = 0
+            for location in self.locations:
+                location.top = acid.ry[0]
+        elif self.location.bottom > acid.get_level():
+            self.vshifts[self.DOWN].time = 0
+            for location in self.locations:
+                location.bottom = acid.get_level()
+        self.electric.location.centery = self.location.centery + 13
         self.electric.update()
         Strip.update(self)
 
@@ -200,3 +219,14 @@ class Triangle(Sprite):
     def update(self):
         self.move(dy=1)
         Sprite.update(self)
+
+
+class Acid(GameChild):
+
+    def __init__(self, parent):
+        GameChild.__init__(self, parent)
+        self.ry = 160, 640
+        self.space = 1
+
+    def get_level(self):
+        return self.space * (self.ry[1] - self.ry[0]) + self.ry[0]