summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergiusz Bazański <q3k@q3k.org>2012-11-11 17:09:15 +0100
committerSergiusz Bazański <q3k@q3k.org>2012-11-11 17:09:15 +0100
commitb045831c1e3b8d6158ab963ad1de93410007c116 (patch)
tree2f27c3a0b301824194b3d59bfe08b75aed4c7768
parent3f60dfa460b44493d8e6cdb37265373e9281dc97 (diff)
downloadlaserz_und_stuff-b045831c1e3b8d6158ab963ad1de93410007c116.tar.gz
laserz_und_stuff-b045831c1e3b8d6158ab963ad1de93410007c116.tar.bz2
laserz_und_stuff-b045831c1e3b8d6158ab963ad1de93410007c116.zip
Fixes and stuff.
-rw-r--r--Lasers_und_stuff/Cannon.py9
-rw-r--r--Lasers_und_stuff/main.py16
2 files changed, 12 insertions, 13 deletions
diff --git a/Lasers_und_stuff/Cannon.py b/Lasers_und_stuff/Cannon.py
index 5d1a8a0..274186a 100644
--- a/Lasers_und_stuff/Cannon.py
+++ b/Lasers_und_stuff/Cannon.py
@@ -82,6 +82,7 @@ class CannonController :
data.extend(self.position)
if(self.fired):
data.append(255)
+ self.fired = False
else:
data.append(0)
if(self.laser):
@@ -116,8 +117,12 @@ class HackWAWCannonController(CannonController):
AXIS_DISTANCE = 20
ARM_LENGTH = 1
def translate_yaw(self, yaw):
- turret_angle = (yaw * math.pi) / 256 - (math.pi / 2)
- servo_angle = math.asin((self.ARM_LENGTH * math.tan(turret_angle)) / (self.AXIS_DISTANCE - self.ARM_LENGTH))
+ return yaw
+ try:
+ turret_angle = (yaw * math.pi) / 256 - (math.pi / 2)
+ servo_angle = math.asin((self.ARM_LENGTH * math.tan(turret_angle)) / (self.AXIS_DISTANCE - self.ARM_LENGTH))
+ except:
+ return 0 if yaw == 0 else 255
return int(((servo_angle + (math.pi / 2)) * 256) / math.pi)
class Gunpoint :
diff --git a/Lasers_und_stuff/main.py b/Lasers_und_stuff/main.py
index 55962e4..dce13e1 100644
--- a/Lasers_und_stuff/main.py
+++ b/Lasers_und_stuff/main.py
@@ -11,6 +11,7 @@ import threading
import os
import signal
import json
+import traceback
from pygame.locals import *
from Cannon import HackWAWCannonController
from Cannon import Gunpoint
@@ -79,13 +80,8 @@ def main():
if event.type == pygame.QUIT:
keep_running = False
elif event.type == KEYUP :
- cannon.send_data()
if event.key == K_SPACE:
-
- if cannon.fired:
- cannon.fired = False
- else:
- cannon.fired = True
+ cannon.fire()
elif event.key == K_RIGHT:
cannon.move_right(20)
elif event.key == K_LEFT:
@@ -113,6 +109,7 @@ def main():
gunpoint.calibrate(point1, point2, point3)
print gunpoint.horizontal_angle, gunpoint.vertical_angle
screen.communicates.append("Calibrated")
+ cannon.send_data()
elif event.type == MOUSEBUTTONUP:
screen.change_color()
@@ -197,10 +194,7 @@ class Screen:
def draw_surface(self, cannon):
self.window.fill(self.color)
for i, text in enumerate(self.communicates):
- self.print_text(text, 20, 20 + i*20, (0, 0, 0), 30, self.window)
-
- if cannon.fired:
- self.print_text("Fired!", 20, 150, (150, 20, 40), 40, self.window)
+ 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)
pygame.display.flip()
@@ -217,7 +211,7 @@ if __name__ == '__main__':
try:
main()
except Exception as e:
- print "Pygame thread raised exception %s" % str(e)
+ traceback.print_exc()
os.kill(os.getpid(), signal.SIGINT)
t = threading.Thread(target=pygame_runner)