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):
|
|
|
|
self.player = player
|
|
|
|
self.game = game
|
|
|
|
|
|
|
|
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):
|
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-04-27 21:49:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def turn_left(self):
|
|
|
|
self.player.rot -= 90
|
|
|
|
|
|
|
|
def turn_right(self):
|
|
|
|
self.player.rot += 90
|
|
|
|
|
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()
|
|
|
|
print(f'ROT: {self.player.rot}')
|
|
|
|
print("Agent pos: ", math.floor(self.player.pos[0] / TILESIZE), math.floor(self.player.pos[1] / TILESIZE))
|