From dab79a6a803a90a086cc3f82a4485d83ff90676e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergiusz=20Baza=C5=84ski?= Date: Sun, 11 Nov 2012 17:25:06 +0100 Subject: [PATCH] New fire code. --- Lasers_und_stuff/main.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Lasers_und_stuff/main.py b/Lasers_und_stuff/main.py index 1115a0a..3b3851c 100644 --- a/Lasers_und_stuff/main.py +++ b/Lasers_und_stuff/main.py @@ -30,31 +30,36 @@ cannon = None @app.route("/left/", methods=["POST"]) def move_left(amount): cannon.move_left(amount) + cannon.send_data() return "OK" @app.route("/right/", methods=["POST"]) def move_right(amount): cannon.move_right(amount) + cannon.send_data() return "OK" @app.route("/up/", methods=["POST"]) def move_up(amount): cannon.move_up(amount) + cannon.send_data() return "OK" @app.route("/down/", methods=["POST"]) def move_down(amount): cannon.move_down(amount) + cannon.send_data() return "OK" -@app.route("/fire/", methods=["POST"]) +@app.route("/fire", methods=["POST"]) def fire(): - cannon.fire(); + cannon.fire() + cannon.send_data() @app.route("/stop_fire/", methods=["POST"]) def stop_fire(): - cannon.fired = False; - + pass + @app.route("/status") def status(): return json.dumps(cannon.get_data()) @@ -66,8 +71,11 @@ def root(): #Camera stuff -camera = pygame.camera.Camera("/dev/video0", (640, 480)) -camera.start() +try: + camera = pygame.camera.Camera("/dev/video0", (640, 480)) + camera.start() +except: + camera = None def main(): @@ -226,8 +234,9 @@ class Screen: self.print_text(text, 20, 20 + i*20, (0, 0, 0), 30, self.window) self.print_text([str(x) for x in cannon.get_data()].__str__(), 20, 300, (0, 0, 0), 30, self.window) - image = camera.get_image() - self.window.blit(image, (CAMERA_X, CAMERA_Y)) + if camera: + image = camera.get_image() + self.window.blit(image, (CAMERA_X, CAMERA_Y)) pygame.display.flip()