4th part of AStar implementation

This commit is contained in:
Marcin Dobrowolski 2020-04-28 18:56:50 +02:00
parent 0fa109ef35
commit 7a65079aa2
3 changed files with 15 additions and 10 deletions

18
main.py
View File

@ -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)

View File

@ -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