diff --git a/game_objects/aiPlayer.py b/game_objects/aiPlayer.py index 62683f9..e79482e 100644 --- a/game_objects/aiPlayer.py +++ b/game_objects/aiPlayer.py @@ -18,8 +18,6 @@ class aiPlayer(): self.player.update() self.game.draw() # print(self.player.get_actual_coords()) - - def turn_left(self): change = int(self.player.rotation()) - 1 @@ -42,5 +40,5 @@ class aiPlayer(): self.turn_right() if action == '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)) \ No newline at end of file + # print(f'ROT: {self.player.rot}') + # print("Agent pos: ", math.floor(self.player.pos[0] / TILESIZE), math.floor(self.player.pos[1] / TILESIZE)) \ No newline at end of file diff --git a/game_objects/player.py b/game_objects/player.py index cc4bd3d..ce88e6d 100644 --- a/game_objects/player.py +++ b/game_objects/player.py @@ -26,14 +26,13 @@ class Player(pg.sprite.Sprite): def set_rotation(self, rotation): self.__rotation = rotation if (rotation == a_star_utils.Rotation.UP or rotation == int(a_star_utils.Rotation.UP)): - self.rot = 90 + self.rot = -90 elif (rotation == a_star_utils.Rotation.RIGHT or rotation == int(a_star_utils.Rotation.RIGHT)): self.rot = 0 elif (rotation == a_star_utils.Rotation.DOWN or rotation == int(a_star_utils.Rotation.DOWN)): - self.rot = 270 + self.rot = 90 elif (rotation == a_star_utils.Rotation.LEFT or rotation == int(a_star_utils.Rotation.LEFT)): self.rot = 180 - def get_keys(self): self.rot_speed = 0 @@ -51,8 +50,12 @@ class Player(pg.sprite.Sprite): def update(self): self.get_keys() - self.rot = (self.rot + self.rot_speed * self.game.dt) % 360 - self.image = pg.transform.rotate(self.game.player_img, self.rot) + # must be fix for manual movement + # self.rot = (self.rot + self.rot_speed * self.game.dt) % 360 + image_rotation = self.rot + if(abs(image_rotation) == 90): + image_rotation *= -1 + self.image = pg.transform.rotate(self.game.player_img, image_rotation) self.rect = self.image.get_rect() self.rect.center = self.pos self.pos += self.vel * self.game.dt diff --git a/main.py b/main.py index aea7a81..5410883 100644 --- a/main.py +++ b/main.py @@ -123,7 +123,8 @@ class Game(): self.debug_mode = not self.debug_mode if event.type == pg.MOUSEBUTTONUP: pos = pg.mouse.get_pos() - clicked_coords = [math.floor(pos[0] / TILESIZE), math.floor(pos[1] / TILESIZE)] + offset_x, offset_y = self.camera.offset() + clicked_coords = [math.floor(pos[0] / TILESIZE) - offset_x, math.floor(pos[1] / TILESIZE) - offset_y] actions = a_star.search_path(math.floor(self.player.pos[0] / TILESIZE), math.floor(self.player.pos[1] / TILESIZE), self.player.rotation(), clicked_coords[0], clicked_coords[1], self.mapArray) print(actions) t = aiPlayer.aiPlayer(self.player, game=self) diff --git a/map/map_utils.py b/map/map_utils.py index adf40e0..f889e2c 100644 --- a/map/map_utils.py +++ b/map/map_utils.py @@ -47,6 +47,10 @@ class Camera: def apply_rect(self, rect): return rect.move(self.camera.topleft) + + def offset(self): + x, y = self.camera.topleft + return x//TILE_SIZE_PX, y//TILE_SIZE_PX def update(self,target): x = -target.rect.x + int(WIDTH/2)