integrate_a_star_and_movement #22

Merged
s462072 merged 6 commits from integrate_a_star_and_movement into master 2022-05-06 13:10:06 +02:00
2 changed files with 9 additions and 11 deletions
Showing only changes of commit eec3b64849 - Show all commits

View File

@ -22,7 +22,7 @@ class aiPlayer():
self.game.update() self.game.update()
self.player.update() self.player.update()
self.game.draw() 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): def startAiController(self, actions):
for action in actions: for action in actions:
if action == 'straight': if action == 'forward':
self.moveAiPlayer() self.moveAiPlayer()
print(f'ROT IS {self.player.rot}') print(f'ROT IS {self.player.rot}')
if action == 'right': if action == 'right':

16
main.py
View File

@ -9,7 +9,7 @@ from settings import *
from map import map from map import map
from map import map_utils from map import map_utils
from path_search_algorthms import bfs 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 from game_objects import aiPlayer
@ -24,7 +24,7 @@ class Game():
self.init_game() self.init_game()
# because dont work without data.txt # because dont work without data.txt
# self.init_bfs() # self.init_bfs()
# self.init_a_star() self.init_a_star()
self.dt = self.clock.tick(FPS) / 1000.0 self.dt = self.clock.tick(FPS) / 1000.0
@ -36,7 +36,7 @@ class Game():
self.agentSprites = pg.sprite.Group() self.agentSprites = pg.sprite.Group()
# player obj # player obj
self.player = Player(self, 32, 100) self.player = Player(self, 32, 32)
# camera obj # camera obj
self.camera = map_utils.Camera(MAP_WIDTH_PX, MAP_HEIGHT_PX) 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 # game loop - set self.playing = False to end the game
self.playing = True self.playing = True
actions = ['right', 'straight', 'straight', 'left', 'straight'
]
t = aiPlayer.aiPlayer(self.player, game=self)
t.startAiController(actions=actions)
while self.playing: while self.playing:
self.dt = self.clock.tick(FPS) / 1000.0 self.dt = self.clock.tick(FPS) / 1000.0
self.events() self.events()
@ -129,7 +124,10 @@ class Game():
if event.type == pg.MOUSEBUTTONUP: if event.type == pg.MOUSEBUTTONUP:
pos = pg.mouse.get_pos() pos = pg.mouse.get_pos()
clicked_coords = [math.floor(pos[0] / TILESIZE), math.floor(pos[1] / TILESIZE)] 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): def show_start_screen(self):
pass pass