/
manual_control.py
46 lines (37 loc) · 1.08 KB
/
manual_control.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pygame
import cannon
import time
size = 240, 240
pygame.init()
screen = pygame.display.set_mode(size)
cannon = cannon.Cannon()
pan_angle = 0.
tilt_angle = 0.
pan_spd = 0
tilt_spd = 0
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
done = True
if event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
state = 0
if event.type == pygame.KEYDOWN: state = 1
if event.key == pygame.K_UP:
tilt_spd = state
if event.key == pygame.K_DOWN:
tilt_spd = -state
if event.key == pygame.K_LEFT:
pan_spd = -state
if event.key == pygame.K_RIGHT:
pan_spd = state
if event.key == pygame.K_SPACE and state:
cannon.fire()
if event.key == pygame.K_ESCAPE:
pygame.quit()
done = True
pan_angle += pan_spd
tilt_angle += tilt_spd
cannon.set_pan_tilt(pan_angle, tilt_angle)
time.sleep(0.1)