2022-04-28 20:12:46 +02:00
|
|
|
from game_objects.player import Player
|
2022-04-27 21:49:17 +02:00
|
|
|
import pygame as pg
|
2022-04-28 18:43:15 +02:00
|
|
|
import math
|
|
|
|
from settings import *
|
2022-04-27 21:49:17 +02:00
|
|
|
vec = pg.math.Vector2
|
|
|
|
|
|
|
|
class aiPlayer():
|
|
|
|
def __init__(self, player, game):
|
2022-04-28 20:12:46 +02:00
|
|
|
self.player : Player = player
|
2022-04-27 21:49:17 +02:00
|
|
|
self.game = game
|
|
|
|
|
|
|
|
def moveAiPlayer(self):
|
|
|
|
for i in range(64 * 1):
|
2022-04-28 18:43:15 +02:00
|
|
|
self.player.pos += vec(1, 0).rotate(self.player.rot)
|
2022-04-27 21:49:17 +02:00
|
|
|
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()
|
2022-04-28 17:21:35 +02:00
|
|
|
# print(self.player.get_actual_coords())
|
2022-05-13 12:47:08 +02:00
|
|
|
|
2022-04-27 21:49:17 +02:00
|
|
|
|
|
|
|
def turn_left(self):
|
2022-04-28 20:12:46 +02:00
|
|
|
change = int(self.player.rotation()) - 1
|
|
|
|
if(change == -1):
|
|
|
|
change = 3
|
|
|
|
self.player.set_rotation(change)
|
2022-04-27 21:49:17 +02:00
|
|
|
|
|
|
|
def turn_right(self):
|
2022-04-28 20:12:46 +02:00
|
|
|
change = int(self.player.rotation()) + 1
|
|
|
|
if(change == 4):
|
|
|
|
change = 0
|
|
|
|
self.player.set_rotation(change)
|
2022-04-27 21:49:17 +02:00
|
|
|
|
2022-04-27 21:51:09 +02:00
|
|
|
def startAiController(self, actions):
|
2022-04-27 21:49:17 +02:00
|
|
|
for action in actions:
|
2022-04-28 17:21:35 +02:00
|
|
|
if action == 'forward':
|
2022-04-27 21:49:17 +02:00
|
|
|
self.moveAiPlayer()
|
2022-04-28 18:43:15 +02:00
|
|
|
# print(f'ROT IS {self.player.rot}')
|
2022-04-27 21:49:17 +02:00
|
|
|
if action == 'right':
|
|
|
|
self.turn_right()
|
|
|
|
if action == 'left':
|
2022-04-28 18:43:15 +02:00
|
|
|
self.turn_left()
|
2022-04-28 21:28:03 +02:00
|
|
|
# print(f'ROT: {self.player.rot}')
|
|
|
|
# print("Agent pos: ", math.floor(self.player.pos[0] / TILESIZE), math.floor(self.player.pos[1] / TILESIZE))
|