integrate movement and a*

This commit is contained in:
s464947 2022-04-28 17:21:35 +02:00
parent 6d07658c47
commit eec3b64849
2 changed files with 9 additions and 11 deletions

View File

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

16
main.py
View File

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