diff --git a/main.py b/main.py index 4be355f..91a926b 100644 --- a/main.py +++ b/main.py @@ -14,11 +14,10 @@ if __name__ == "__main__": # init functions graphics.drawBackground(waiter.matrix) - graphics.update(waiter.X, waiter.Y) + graphics.update(waiter) goal = None - path = [(0, 0)] - # print(waiter.findPath()) + path = '' while True: for event in pygame.event.get(): if event.type == pygame.QUIT: @@ -43,19 +42,12 @@ if __name__ == "__main__": goal = (x, y) path = waiter.findPath(goal) - print('goal: {}'.format(goal)) + path = waiter.translatePath(path) - if path != []: - print(path) - nextStep = path.pop(0) - print(nextStep) + if path != '': + nextStep = path[0] + path = path[1:] 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) diff --git a/resources/images/waiter.png b/resources/images/waiter_E.png similarity index 100% rename from resources/images/waiter.png rename to resources/images/waiter_E.png diff --git a/resources/images/waiter_N.png b/resources/images/waiter_N.png new file mode 100644 index 0000000..ca80335 Binary files /dev/null and b/resources/images/waiter_N.png differ diff --git a/resources/images/waiter_S.png b/resources/images/waiter_S.png new file mode 100644 index 0000000..ca80335 Binary files /dev/null and b/resources/images/waiter_S.png differ diff --git a/resources/images/waiter_W.png b/resources/images/waiter_W.png new file mode 100644 index 0000000..ca80335 Binary files /dev/null and b/resources/images/waiter_W.png differ diff --git a/src/__pycache__/graphics.cpython-38.pyc b/src/__pycache__/graphics.cpython-38.pyc index af0895d..431c48a 100644 Binary files a/src/__pycache__/graphics.cpython-38.pyc and b/src/__pycache__/graphics.cpython-38.pyc differ diff --git a/src/__pycache__/waiter.cpython-38.pyc b/src/__pycache__/waiter.cpython-38.pyc index 5807d50..28e871c 100644 Binary files a/src/__pycache__/waiter.cpython-38.pyc and b/src/__pycache__/waiter.cpython-38.pyc differ diff --git a/src/graphics.py b/src/graphics.py index b593205..152e2e1 100644 --- a/src/graphics.py +++ b/src/graphics.py @@ -5,32 +5,47 @@ class Graphics: def __init__(self): self.image = { 'floor': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/floor.jpg'), - 'wall': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/wall.png'), # - 'bar': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/table3.png'), # - 'bar_floor': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/waiter.png'), + # + 'wall': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/wall.png'), + # + 'bar': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/table3.png'), + 'bar_floor': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/waiter_N.png'), 'table': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/table3.png'), - 'waiter': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/waiter.png'), - 'chair_front': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/chair-front.png'), # - 'chair_back': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/chair-back.png'), # - 'chair_left': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/chair-left.png'), # - 'chair_right': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/chair-right.png') # + 'waiter_N': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/waiter_N.png'), + 'waiter_S': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/waiter_S.png'), + 'waiter_E': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/waiter_E.png'), + 'waiter_W': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/waiter_W.png'), + # + 'chair_front': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/chair-front.png'), + # + 'chair_back': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/chair-back.png'), + # + 'chair_left': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/chair-left.png'), + # + 'chair_right': pygame.image.load('/Users/marcindobrowolski/Desktop/Python/Sztuczna_Inteligencja_2020/resources/images/chair-right.png') } self.block_size = 50 self.height = 15 self.width: int = 14 - self.screen = pygame.display.set_mode((self.block_size * self.width, self.block_size * self.height)) + self.screen = pygame.display.set_mode( + (self.block_size * self.width, self.block_size * self.height)) def drawBackground(self, matrix): for y in range(self.height): for x in range(self.width): - self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size)) + self.screen.blit( + self.image['floor'], (x * self.block_size, y * self.block_size)) for y in range(self.height): for x in range(self.width): - self.screen.blit(self.image[matrix.get_type(x, y)], (x * self.block_size, y * self.block_size)) + self.screen.blit(self.image[matrix.get_type( + x, y)], (x * self.block_size, y * self.block_size)) def clear(self, x, y): - self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size)) + self.screen.blit(self.image['floor'], + (x * self.block_size, y * self.block_size)) - def update(self, x, y): - self.screen.blit(self.image['waiter'], (x * self.block_size, y * self.block_size)) + def update(self, waiter): + model = 'waiter_' + waiter.direction + self.screen.blit( + self.image[model], (waiter.X * self.block_size, waiter.Y * self.block_size)) diff --git a/src/waiter.py b/src/waiter.py index be879b1..122cdde 100644 --- a/src/waiter.py +++ b/src/waiter.py @@ -55,11 +55,9 @@ class Waiter(pygame.sprite.Sprite): # AStar def findPath(self, goal): - # Stworzenie startowego i koncowego wierzcholka startNode = self.matrix.matrix[self.X][self.Y] goalNode = self.matrix.matrix[goal[0]][goal[1]] - # Inicjalizacja list openList = [] closedList = [] @@ -72,7 +70,6 @@ class Waiter(pygame.sprite.Sprite): currentNode = openList.pop(0) closedList.append(currentNode) - # Tutaj odbywac sie bedzie budowanie sciezki gdy algorytm osiagnie cel if currentNode == goalNode: path = [] current = currentNode @@ -230,24 +227,21 @@ class Waiter(pygame.sprite.Sprite): return output - def travel(self, goal, graphics): - translatedPath = self.translatePath([goal]) - print('{} - {} - {}'.format(self.direction, goal, translatedPath)) - for character in translatedPath: - if character == 'F': - graphics.clear(self.X, self.Y) - self.update('F', graphics) - graphics.update(self.X, self.Y) + def travel(self, nextStep, graphics): + if nextStep == 'F': + graphics.clear(self.X, self.Y) + self.update('F', graphics) + graphics.update(self) - if character == 'R': - #graphics.clear(self.X, self.Y) - self.update('R', graphics) - #graphics.update(self.X, self.Y) + if nextStep == 'R': + graphics.clear(self.X, self.Y) + self.update('R', graphics) + graphics.update(self) - if character == 'L': - #graphics.clear(self.X, self.Y) - self.update('L', graphics) - #graphics.update(self.X, self.Y) + if nextStep == 'L': + graphics.clear(self.X, self.Y) + self.update('L', graphics) + graphics.update(self) def getTotalCost(tile):