Trashmaster/game_objects/aiPlayer.py

44 lines
1.5 KiB
Python
Raw Normal View History

2022-04-28 20:12:46 +02:00
from game_objects.player import Player
import pygame as pg
2022-04-28 18:43:15 +02:00
import math
from settings import *
vec = pg.math.Vector2
class aiPlayer():
def __init__(self, player, game):
2022-04-28 20:12:46 +02:00
self.player : Player = player
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)
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())
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)
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:51:09 +02:00
def startAiController(self, actions):
for action in actions:
2022-04-28 17:21:35 +02:00
if action == 'forward':
self.moveAiPlayer()
2022-04-28 18:43:15 +02:00
# print(f'ROT IS {self.player.rot}')
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))