Fixes and stuff.

master
q3k 2012-11-11 17:09:15 +01:00
parent 3f60dfa460
commit b045831c1e
2 changed files with 12 additions and 13 deletions

View File

@ -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 :

View File

@ -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)