diff --git a/game_objects/aiPlayer.py b/game_objects/aiPlayer.py new file mode 100644 index 0000000..5f5c588 --- /dev/null +++ b/game_objects/aiPlayer.py @@ -0,0 +1,46 @@ +import pygame as pg +vec = pg.math.Vector2 + +class aiPlayer(): + def __init__(self, player, game): + self.player = player + self.game = game + self.angle = 0 + + def rotateAiPlayer(self, d: str): + if d == 'left': + print('in left') + self.direction -= 90 + if d == 'right': + self.direction += 90 + + def moveAiPlayer(self): + for i in range(64 * 1): + self.player.pos += vec(1, 0).rotate(self.angle) + self.player.rect.center = self.player.pos + # print(f'START COORDS: {x_s, x_bias}; CURRENT AGENT COORDS: {self.player.get_actual_coords()}') + self.game.update() + self.player.update() + self.game.draw() + print(self.player.get_actual_coords()) + + + + def turn_left(self): + self.player.rot -= 90 + self.angle -= 90 + + def turn_right(self): + self.player.rot += 90 + self.angle += 90 + + def startAiController(self, actions): + + for action in actions: + if action == 'straight': + self.moveAiPlayer() + print(f'ROT IS {self.player.rot}') + if action == 'right': + self.turn_right() + if action == 'left': + self.turn_left() \ No newline at end of file diff --git a/game_objects/player.py b/game_objects/player.py index 918901a..615922d 100644 --- a/game_objects/player.py +++ b/game_objects/player.py @@ -44,4 +44,9 @@ class Player(pg.sprite.Sprite): utils.collide_with_walls(self, self.game.wallTiles, 'x') self.hit_rect.centery = self.pos.y utils.collide_with_walls(self, self.game.wallTiles, 'y') - self.rect.center = self.hit_rect.center \ No newline at end of file + self.rect.center = self.hit_rect.center + + + def get_actual_coords(self): + # return (self.rect.x / 64, self.rect.y / 64) + return (self.rect.x, self.rect.y) \ No newline at end of file diff --git a/main.py b/main.py index 43e22fc..713b383 100644 --- a/main.py +++ b/main.py @@ -4,15 +4,15 @@ import pygame as pg import sys from os import path import math - from map import * 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 class Game(): def __init__(self): @@ -22,8 +22,11 @@ class Game(): pg.display.set_caption("Trashmaster") self.load_data() 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 def init_game(self): # initialize all variables and do all the setup for a new game @@ -75,8 +78,14 @@ class Game(): def run(self): # 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.dt = self.clock.tick(FPS) / 1000.0 self.events() self.update() self.draw() @@ -129,8 +138,10 @@ class Game(): pass # create the game object -g = Game() -g.show_start_screen() -while True: + +if __name__ == "__main__": + g = Game() + g.show_start_screen() + g.run() - g.show_go_screen() + g.show_go_screen() \ No newline at end of file diff --git a/map/map_pattern.py b/map/map_pattern.py index e5fb4fb..c129396 100644 --- a/map/map_pattern.py +++ b/map/map_pattern.py @@ -12,6 +12,6 @@ def load_img(path): def get_pattern(): return { - 0: load_img(ROAD_DIR+"GTA2_TILE_257.bmp"), - 1: load_img(BUILDING_DIR+"GTA2_TILE_187.bmp"), + 0: load_img("resources/textures/road/GTA2_TILE_257.bmp"), + 1: load_img("resources/textures/buliding/GTA2_TILE_187.bmp"), } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index b4fe918..a3b0748 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,17 @@ +astroid==2.11.2 +autopep8==1.6.0 +dill==0.3.4 +flake8==4.0.1 +isort==5.10.1 +lazy-object-proxy==1.7.1 +mccabe==0.6.1 +platformdirs==2.5.1 +pycodestyle==2.8.0 +pyflakes==2.4.0 pygame==2.1.2 +pylint==2.13.5 +PyTMX==3.31 +toml==0.10.2 +tomli==2.0.1 +typing_extensions==4.1.1 +wrapt==1.14.0