-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·63 lines (56 loc) · 1.56 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from time import process_time
from config import *
from rrt import rrt
import drawing
import events
from time import sleep
import pygame as pg
pg.init()
def main():
drawing.screen = pg.display.set_mode((WIDTH, HEIGHT))
gameState = 'waiting'
while True:
event = pg.event.poll()
mousePos = pg.mouse.get_pos()
gameState = events.mainHandler(event, gameState, mousePos)
if gameState == 'quit':
print(gameState)
return
elif gameState == 'start-positioning':
drawing.startPos = mousePos
elif gameState == 'goal-positioning':
drawing.goalPos = mousePos
elif gameState == 'drawing':
drawing.drawObstacle(mousePos)
elif gameState == 'erasing':
drawing.eraseObstacle(mousePos)
elif gameState == 'clear':
drawing.clearObstacles()
elif gameState == 'save':
drawing.saveObstacles()
elif gameState == 'load':
drawing.loadObstacles()
elif gameState == 'rrt':
print(gameState)
drawing.recorder = True
drawing.clearEdgesPool()
tree = rrt(drawing.startPos, drawing.goalPos, drawing.obstaclesSurface)
if tree: # A path was found:
drawing.drawPath(tree)
gameState = 'path-found'
else: # User terminated the algorithm's execution:
drawing.recorder = False
gameState = 'waiting'
elif drawing.run_algo:
drawing.recorder = True
drawing.clearEdgesPool()
tree = rrt(drawing.startPos, drawing.goalPos, drawing.obstaclesSurface)
if tree: # A path was found:
drawing.drawPath(tree)
drawing.run_algo = False
drawing.update()
sleep(1)
return
# drawing.update()
if __name__ == '__main__':
main()