summaryrefslogtreecommitdiffstats
path: root/Lasers_und_stuff/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lasers_und_stuff/main.py')
-rw-r--r--Lasers_und_stuff/main.py38
1 files changed, 35 insertions, 3 deletions
diff --git a/Lasers_und_stuff/main.py b/Lasers_und_stuff/main.py
index 55962e4..f652b37 100644
--- a/Lasers_und_stuff/main.py
+++ b/Lasers_und_stuff/main.py
@@ -14,10 +14,15 @@ import json
from pygame.locals import *
from Cannon import HackWAWCannonController
from Cannon import Gunpoint
+import pygame.camera
app = flask.Flask(__name__)
app.debug = True
pygame.init()
+pygame.camera.init()
+
+CAMERA_X = 400
+CAMERA_Y = 30
cannon = None
@@ -41,17 +46,32 @@ def move_down(amount):
cannon.move_down(amount)
return "OK"
+@app.route("/fire/", methods=["POST"])
+def fire():
+ cannon.fire();
+
+@app.route("/stop_fire/", methods=["POST"])
+def stop_fire():
+ cannon.fired = False;
+
@app.route("/status")
def status():
return json.dumps(cannon.get_data())
@app.route("/")
def root():
-
return flask.render_template("status.html", data=cannon.get_data())
+
+
+#Camera stuff
+
+camera = pygame.camera.Camera("/dev/video0", (640, 480))
+camera.start()
+
+
def main():
#create the screen
- window = pygame.display.set_mode((800, 600))
+ window = pygame.display.set_mode((1200, 800))
GRAY = ( 182, 182, 182)
VIOLET = (150, 100, 190)
@@ -71,6 +91,7 @@ def main():
gunpoint = Gunpoint((5, 4), (200, 4), (5, 210))
+
keep_running = True
while keep_running:
screen.draw_surface(cannon)
@@ -115,6 +136,14 @@ def main():
screen.communicates.append("Calibrated")
elif event.type == MOUSEBUTTONUP:
+ mousex, mousey = pygame.mouse.get_pos()
+ print mousex, mousey
+ x = (mousex - CAMERA_X)/640.0
+ y = (CAMERA_Y + 480 - mousey)/480.0
+ print x, y
+ position = gunpoint.aim((x, y))
+ print position
+ cannon.position = position
screen.change_color()
print "Pygame thread exited."
os.kill(os.getpid(), signal.SIGINT)
@@ -202,7 +231,10 @@ class Screen:
if cannon.fired:
self.print_text("Fired!", 20, 150, (150, 20, 40), 40, self.window)
- self.print_text([str(x) for x in cannon.get_data()].__str__(), 20, 300, (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))
+
pygame.display.flip()
def print_text(self, text,xx,yy,color,text_size, screen):