shft
authorFrank DeMarco <frank.s.demarco@gmail.com>
Fri, 25 Apr 2014 18:37:23 +0000 (03:37 +0900)
committerFrank DeMarco <frank.s.demarco@gmail.com>
Fri, 25 Apr 2014 18:37:23 +0000 (03:37 +0900)
scale_sieve/ScaleSieve.py

index 4716edd..3efad43 100644 (file)
@@ -22,14 +22,33 @@ class ScaleSieve(Game):
 
 class Strip(Sprite):
 
+    LEFT, RIGHT = range(2)
+
     def __init__(self, parent):
         Sprite.__init__(self, parent)
         self.display_surface = self.get_display_surface()
+        self.delegate = self.get_game().delegate
+        self.shifting = [False, False]
         self.add_frames()
+        self.subscribe(self.respond)
 
     def add_frames(self):
         pass
 
+    def respond(self, event):
+        compare = self.delegate.compare
+        if compare(event, "left") or compare(event, "left", True):
+            self.shifting[self.LEFT] = not event.cancel
+        elif compare(event, "right") or compare(event, "right", True):
+            self.shifting[self.RIGHT] = not event.cancel
+
+    def update(self):
+        if self.shifting[self.LEFT]:
+            self.move(3)
+        if self.shifting[self.RIGHT]:
+            self.move(-3)
+        Sprite.update(self)
+
 
 class Sieve(Strip):