-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_robot.py
More file actions
65 lines (46 loc) · 1.45 KB
/
python_robot.py
File metadata and controls
65 lines (46 loc) · 1.45 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pygame
import threading
window_width = 800
window_height = 800
win = pygame.display.set_mode((window_width, window_height))
#pygame.display.set_caption("Manchester Robot")
stop_event = threading.Event()
class Robot():
def __init__(self):
self.x = 200
self.y = 200
self.width = 20
self.height = 20
self.xvel = 0
self.run = True
def forward(self):
self.xvel = 10
def stop(self):
self.xvel = 0
def start(self):
pygame.init()
while not stop_event.is_set():
if (not self.run):
stop_event.set()
else:
for event in pygame.event.get():
if event.type == pygame.QUIT:
stop_event.set()
pygame.time.delay(10)
if (self.x < window_width - 20):
self.x += self.xvel
else:
self.x = window_width - 20
win.fill((0,0,0))
pygame.draw.rect(win, (255,0,0), (self.x, self.y, self.width, self.height))
pygame.display.update()
print("stopping")
pygame.quit()
def quit(self):
print("called quit")
self.run = False
robot = Robot()
def start_simulator():
robot.start();
robot_thread = threading.Thread(target=start_simulator)
# robot_thread.start()