From eec3b64849d4e3f72f12dfe7b917a7920bf5ce0d Mon Sep 17 00:00:00 2001 From: s464947 Date: Thu, 28 Apr 2022 17:21:35 +0200 Subject: [PATCH] integrate movement and a* --- game_objects/aiPlayer.py | 4 ++-- main.py | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/game_objects/aiPlayer.py b/game_objects/aiPlayer.py index 5f5c588..a3239dd 100644 --- a/game_objects/aiPlayer.py +++ b/game_objects/aiPlayer.py @@ -22,7 +22,7 @@ class aiPlayer(): self.game.update() self.player.update() self.game.draw() - print(self.player.get_actual_coords()) + # print(self.player.get_actual_coords()) @@ -37,7 +37,7 @@ class aiPlayer(): def startAiController(self, actions): for action in actions: - if action == 'straight': + if action == 'forward': self.moveAiPlayer() print(f'ROT IS {self.player.rot}') if action == 'right': diff --git a/main.py b/main.py index 713b383..2cd9212 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ from settings import * from map import map from map import map_utils from path_search_algorthms import bfs -# from path_search_algorthms import a_star +from path_search_algorthms import a_star from game_objects import aiPlayer @@ -24,7 +24,7 @@ class Game(): self.init_game() # because dont work without data.txt # self.init_bfs() - # self.init_a_star() + self.init_a_star() self.dt = self.clock.tick(FPS) / 1000.0 @@ -36,7 +36,7 @@ class Game(): self.agentSprites = pg.sprite.Group() # player obj - self.player = Player(self, 32, 100) + self.player = Player(self, 32, 32) # camera obj self.camera = map_utils.Camera(MAP_WIDTH_PX, MAP_HEIGHT_PX) @@ -79,11 +79,6 @@ class Game(): # game loop - set self.playing = False to end the game self.playing = True - actions = ['right', 'straight', 'straight', 'left', 'straight' - ] - t = aiPlayer.aiPlayer(self.player, game=self) - t.startAiController(actions=actions) - while self.playing: self.dt = self.clock.tick(FPS) / 1000.0 self.events() @@ -129,7 +124,10 @@ class Game(): if event.type == pg.MOUSEBUTTONUP: pos = pg.mouse.get_pos() clicked_coords = [math.floor(pos[0] / TILESIZE), math.floor(pos[1] / TILESIZE)] - print(clicked_coords) + actions = a_star.search_path(math.floor(self.player.pos[0] / TILESIZE), math.floor(self.player.pos[1] / TILESIZE), clicked_coords[0], clicked_coords[1], self.mapArray) + print(actions) + t = aiPlayer.aiPlayer(self.player, game=self) + t.startAiController(actions=actions) def show_start_screen(self): pass