-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
34 lines (27 loc) · 880 Bytes
/
demo.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
"""Game runner"""
import time
import pygame
import newt
import pathing
import draw
import obstacle
START = newt.Node(0, 0, 0, 0, 1)
GOAL = newt.Node(100, 100, 0, 0, 0)
def get_path(obstacles, bounds):
"""return nodes in path from A*"""
heuristic = lambda n, g: newt.heuristic(n, g, obstacles, bounds)
return pathing.a_star(START, GOAL, newt.adjacent, heuristic, newt.success)
def main():
"""generate path and render"""
obstacles = obstacle.get_obstacles(START.x, START.y, GOAL.x, GOAL.y)
bounds = (GOAL.x, GOAL.y)
window = draw.init(obstacles, GOAL)
pygame.display.flip()
begin = time.time()
path = get_path(obstacles, bounds)
end = time.time()
print("time: " + str(end - begin))
draw.animate_path(window, obstacles, GOAL, path)
if __name__ == "__main__":
while True:
main()