X-Git-Url: https://git.yukkurigames.com/?p=python-bulletml.git;a=blobdiff_plain;f=bulletml-runner;h=7ad5addd678ada824c88385ed2a08d625ea90231;hp=fc57bcedd82f92929ed28c09b54602d1e668b73c;hb=2e2790231b49d4a2ed9299825ac0cf8121a655e2;hpb=b246fe5b1c35b4d0a189e7c28597927e6e5241e8;ds=sidebyside diff --git a/bulletml-runner b/bulletml-runner index fc57bce..7ad5add 100755 --- a/bulletml-runner +++ b/bulletml-runner @@ -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,11 +45,20 @@ 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: + for obj in list(active): new = obj.step() total += len(new) @@ -70,11 +85,20 @@ 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) + for event in pygame.event.get(): + if event.type == pygame.QUIT: + raise SystemExit + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_SPACE: + paused ^= True + elif event.key == pygame.K_RIGHT: + go = True + print " Finished: %04d: %d bullets." % (frames, total) if __name__ == "__main__":