slide
authorFrank DeMarco <frank.s.demarco@gmail.com>
Fri, 25 Apr 2014 19:25:07 +0000 (04:25 +0900)
committerFrank DeMarco <frank.s.demarco@gmail.com>
Fri, 25 Apr 2014 19:25:07 +0000 (04:25 +0900)
config
scale_sieve/ScaleSieve.py

diff --git a/config b/config
index f2bb5d6..f0b8d75 100644 (file)
--- a/config
+++ b/config
@@ -5,4 +5,5 @@ dimensions = 420, 700
 quit = K_ESCAPE
 
 [interpolate]
-scale = C 0 10, 1000 80
+scale = C 0.0 10.0, 1000.0 80.0
+shift = C 0.0 0.0, 1500 4.0, 2000.0 6.0
index 3efad43..5fe8d79 100644 (file)
@@ -28,7 +28,8 @@ class Strip(Sprite):
         Sprite.__init__(self, parent)
         self.display_surface = self.get_display_surface()
         self.delegate = self.get_game().delegate
-        self.shifting = [False, False]
+        self.shifts = Shift(self, 1), Shift(self, -1)
+        self.shift_nodeset = self.get_game().interpolator.get_nodeset("shift")
         self.add_frames()
         self.subscribe(self.respond)
 
@@ -38,18 +39,41 @@ class Strip(Sprite):
     def respond(self, event):
         compare = self.delegate.compare
         if compare(event, "left") or compare(event, "left", True):
-            self.shifting[self.LEFT] = not event.cancel
+            self.shifts[self.LEFT].active = not event.cancel
         elif compare(event, "right") or compare(event, "right", True):
-            self.shifting[self.RIGHT] = not event.cancel
+            self.shifts[self.RIGHT].active = not event.cancel
 
     def update(self):
-        if self.shifting[self.LEFT]:
-            self.move(3)
-        if self.shifting[self.RIGHT]:
-            self.move(-3)
+        for shift in self.shifts:
+            shift.update()
+            if shift.time:
+                self.move(shift.get_dx())
         Sprite.update(self)
 
 
+class Shift(GameChild):
+
+    def __init__(self, parent, direction):
+        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")
+
+    def update(self):
+        least, greatest = self.nodeset[0].x, self.nodeset[-1].x
+        if self.active and self.time < greatest:
+            self.time = min(self.time + self.timer.get_last_frame_duration(),
+                            greatest)
+        elif not self.active and self.time > least:
+            self.time = max(self.time - self.timer.get_last_frame_duration(),
+                            least)
+
+    def get_dx(self):
+        return self.nodeset.get_y(self.time) * self.direction
+
+
 class Sieve(Strip):
 
     def __init__(self, parent):