Get my coordinate systems straight - 0,0 will be upper-left.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 16 Mar 2010 08:45:32 +0000 (01:45 -0700)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 16 Mar 2010 08:45:32 +0000 (01:45 -0700)
bulletml-runner
bulletml/impl.py

index d4919886a39b08b30432bc3a8b8081b172e95e71..7ad5addd678ada824c88385ed2a08d625ea90231 100755 (executable)
@@ -12,11 +12,16 @@ def main(argv):
     bullet = pygame.Surface([3, 3])
     bullet.fill([255, 0, 0])
     filename = argv[0]
-    doc = bulletml.BulletML(open(filename, "rU"))
     clock = pygame.time.Clock()
     target = bulletml.Bullet()
 
+    file_idx = 0
+
+    if not argv:
+        raise SystemExit
+
     while True:
+        doc = bulletml.BulletML(open(argv[file_idx % len(argv)], "rU"))
         source = bulletml.Bullet.FromDoc(
             doc, x=150, y=150, target=target, rank=0.5)
                                          
@@ -27,8 +32,9 @@ def main(argv):
         frames = 0
         total = 0
         paused = False
+        newfile = False
 
-        while active:
+        while active and not newfile:
             go = False
 
             for event in pygame.event.get():
@@ -39,9 +45,17 @@ def main(argv):
                         paused ^= True
                     elif event.key == pygame.K_RIGHT:
                         go = True
+                    elif event.key == pygame.K_PAGEUP:
+                        file_idx -= 1
+                        newfile = True
+                    elif event.key == pygame.K_PAGEDOWN:
+                        file_idx += 1
+                        newfile = True
+                    elif event.key == pygame.K_RETURN:
+                        newfile = True
             target.x, target.y = pygame.mouse.get_pos()
             target.x /= 2
-            target.y = (screen.get_height() - target.y) / 2
+            target.y /= 2
 
             if not paused or go:
 
@@ -71,7 +85,7 @@ def main(argv):
                         y *= 2
                         x -= 1
                         y -= 1
-                        screen.blit(bullet, [x, screen.get_height() - y])
+                        screen.blit(bullet, [x, y])
             pygame.display.flip()
 
             clock.tick(60)
index 2c938d22f8299fbbd4ab5e0ac6de91967a4912ca..6fe1641c2134fe1f231c09bba9654e8711027dae 100644 (file)
@@ -256,7 +256,7 @@ class Bullet(object):
             return self.direction
         else:
             return math.degrees(
-                math.atan2(self.target.x - self.x, self.target.y - self.y))
+                math.atan2(self.target.x - self.x, self.y - self.target.y))
 
     @property
     def finished(self):