AI generálta ütközés
This commit is contained in:
@@ -68,6 +68,7 @@ class OverworldMap:
|
||||
x = 0
|
||||
y = len(OVERWORLD_MAP)
|
||||
for row in OVERWORLD_MAP:
|
||||
y -= 1
|
||||
for tile in row:
|
||||
self.sprites.append([
|
||||
assets.sprites["overworld"].get_texture(
|
||||
@@ -82,9 +83,59 @@ class OverworldMap:
|
||||
)
|
||||
])
|
||||
x += 1
|
||||
y -= 1
|
||||
x = 0
|
||||
# !!! CHATGPT !!!
|
||||
def get_player_world_pos(self, game):
|
||||
"""Calculates the player's world pixel position based on scroll."""
|
||||
base_offset_x = (game.screen_width / 2) - ((OVERWORLD_WIDTH * OVERWORLD_TILE_WIDTH) / 2)
|
||||
base_offset_y = (game.screen_height / 2) - ((OVERWORLD_HEIGHT * OVERWORLD_TILE_HEIGHT) / 2)
|
||||
|
||||
# Player pixel position in the world coordinate space
|
||||
player_world_x = (game.screen_width / 2) - base_offset_x - self.scroll_x
|
||||
player_world_y = (game.screen_height / 2) - base_offset_y - self.scroll_y
|
||||
|
||||
return player_world_x, player_world_y
|
||||
|
||||
def get_tile_at(self, world_x, world_y):
|
||||
"""Returns the map tile ID at a given world pixel position."""
|
||||
tile_x = int(world_x // OVERWORLD_TILE_WIDTH)
|
||||
tile_y = int(world_y // OVERWORLD_TILE_HEIGHT)
|
||||
|
||||
# Check bounds
|
||||
if 0 <= tile_x < OVERWORLD_WIDTH and 0 <= tile_y < OVERWORLD_HEIGHT:
|
||||
return OVERWORLD_MAP[OVERWORLD_HEIGHT - 1 - tile_y][tile_x]
|
||||
return None # Out of bounds / wall
|
||||
|
||||
def is_box_walkable(self, world_x, world_y, width, height):
|
||||
"""Checks if a bounding box (e.g., player's feet) is entirely on walkable tiles."""
|
||||
feet_offset_y = (B_SPRITE_HEIGHT - height) / 2
|
||||
box_center_y = world_y - feet_offset_y
|
||||
|
||||
left = world_x - (width / 2)
|
||||
right = world_x + (width / 2) - 1
|
||||
bottom = box_center_y - (height / 2)
|
||||
top = box_center_y + (height / 2) - 1
|
||||
|
||||
# Check the four corners of the bounding box
|
||||
corners = [
|
||||
(left, bottom),
|
||||
(right, bottom),
|
||||
(left, top),
|
||||
(right, top)
|
||||
]
|
||||
|
||||
for cx, cy in corners:
|
||||
tile_x = int(cx // OVERWORLD_TILE_WIDTH)
|
||||
tile_y = int(cy // OVERWORLD_TILE_HEIGHT)
|
||||
|
||||
# Check map bounds
|
||||
if not (0 <= tile_x < OVERWORLD_WIDTH and 0 <= tile_y < OVERWORLD_HEIGHT):
|
||||
return False # Out of bounds is a wall
|
||||
|
||||
return True
|
||||
|
||||
|
||||
# !!! CHATGPT VÉGE !!!
|
||||
|
||||
def render(self, game):
|
||||
for s in self.sprites:
|
||||
|
||||
Reference in New Issue
Block a user