-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_robot_process.py
More file actions
59 lines (38 loc) · 1.17 KB
/
python_robot_process.py
File metadata and controls
59 lines (38 loc) · 1.17 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
import pygame
import multiprocessing
window_width = 500
window_height = 500
win = pygame.display.set_mode((window_width, window_height))
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 self.run():
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_process = multiprocessing.Process(target=start_simulator)
#robot_process.start()