integrate_a_star_and_movement #22
@ -1,11 +1,12 @@
|
||||
import pygame as pg
|
||||
import math
|
||||
from settings import *
|
||||
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':
|
||||
@ -16,7 +17,7 @@ class aiPlayer():
|
||||
|
||||
def moveAiPlayer(self):
|
||||
for i in range(64 * 1):
|
||||
self.player.pos += vec(1, 0).rotate(self.angle)
|
||||
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()
|
||||
@ -28,19 +29,18 @@ class aiPlayer():
|
||||
|
||||
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 == 'forward':
|
||||
self.moveAiPlayer()
|
||||
print(f'ROT IS {self.player.rot}')
|
||||
# print(f'ROT IS {self.player.rot}')
|
||||
if action == 'right':
|
||||
self.turn_right()
|
||||
if action == 'left':
|
||||
self.turn_left()
|
||||
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))
|
Loading…
Reference in New Issue
Block a user