4th part of AStar implementation
This commit is contained in:
parent
0fa109ef35
commit
7a65079aa2
18
main.py
18
main.py
@ -43,15 +43,19 @@ if __name__ == "__main__":
|
||||
|
||||
goal = (x, y)
|
||||
path = waiter.findPath(goal)
|
||||
print('goal: {}'.format(goal))
|
||||
|
||||
if path != []:
|
||||
temp = path.pop(0)
|
||||
print(temp)
|
||||
waiter.travel(temp, graphics)
|
||||
|
||||
#graphics.clear(waiter.X, waiter.Y)
|
||||
#waiter.update(event, graphics)
|
||||
#graphics.update(waiter.X, waiter.Y)
|
||||
print(path)
|
||||
nextStep = path.pop(0)
|
||||
print(nextStep)
|
||||
waiter.travel(nextStep, graphics)
|
||||
|
||||
print('{} {} current position'.format(waiter.X, waiter.Y))
|
||||
'''
|
||||
graphics.clear(waiter.X, waiter.Y)
|
||||
waiter.update(event, graphics)
|
||||
graphics.update(waiter.X, waiter.Y)
|
||||
'''
|
||||
pygame.display.flip()
|
||||
clock.tick(fps)
|
||||
|
Binary file not shown.
@ -8,8 +8,8 @@ from .tile import Tile
|
||||
class Waiter(pygame.sprite.Sprite):
|
||||
def __init__(self, graphics):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
self.X = 0
|
||||
self.Y = 0
|
||||
self.X = 7
|
||||
self.Y = 7
|
||||
self.frame = 0
|
||||
self.matrix = Matrix(graphics=graphics)
|
||||
self.direction = 'E'
|
||||
@ -63,6 +63,7 @@ class Waiter(pygame.sprite.Sprite):
|
||||
openList = []
|
||||
closedList = []
|
||||
|
||||
startNode.parent = None
|
||||
openList.append(startNode)
|
||||
|
||||
while len(openList) > 0:
|
||||
@ -125,7 +126,7 @@ class Waiter(pygame.sprite.Sprite):
|
||||
for openNode in openList:
|
||||
if child == openNode and child.startCost > openNode.startCost:
|
||||
perm = 1
|
||||
continue
|
||||
break
|
||||
|
||||
if perm == 1:
|
||||
perm = 0
|
||||
|
Loading…
Reference in New Issue
Block a user