From 45261b2c58bad356d1a9676cb2a5fe4c227227a1 Mon Sep 17 00:00:00 2001 From: markojozsef Date: Sat, 10 Oct 2026 17:45:59 +0200 Subject: [PATCH] =?UTF-8?q?AI=20gener=C3=A1lta=20=C3=BCtk=C3=B6z=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/AIHasznalat.md | 5 +++- src/gamestates/overworld.py | 58 +++++++++++++++++++++++++++---------- src/objects.py | 53 ++++++++++++++++++++++++++++++++- 3 files changed, 99 insertions(+), 17 deletions(-) diff --git a/doc/AIHasznalat.md b/doc/AIHasznalat.md index d207b25..407e1ce 100644 --- a/doc/AIHasznalat.md +++ b/doc/AIHasznalat.md @@ -18,5 +18,8 @@ Teljesen AI-generált szakaszokat egy `# !!! CHATGPT !!!` komment jelzi ### gamestates/battle.py * menük +### gamestates/overworld.py és objects.py +* ütközés + ## Dokumentáció -Ezen a fájlon kívül minden dokumentáció AI generálta. \ No newline at end of file +Ezen a fájlon kívül minden dokumentáció AI generálta. diff --git a/src/gamestates/overworld.py b/src/gamestates/overworld.py index 56e059c..3695082 100644 --- a/src/gamestates/overworld.py +++ b/src/gamestates/overworld.py @@ -27,25 +27,26 @@ def start_battle(battle_id): def switch(game): in_battle_transition = False +# !!! CHATGPT !!! def update(game, dt): global btrans_active, btrans_timer if btrans_active: - btrans_timer += dt + btrans_timer += dt if btrans_timer >= BTRANS_DURATION: game.mos_enabled = False btrans_active = False btrans_sound.stop() - gamestate.switch_gamestate(game,"battle") + gamestate.switch_gamestate(game, "battle") game.mos_enabled = True - cycle_progress = (btrans_timer % BTRANS_PULSE_DUR) / BTRANS_PULSE_DUR - game.mosaic = max(1, math.floor(cycle_progress * 16)) + cycle_progress = (btrans_timer % BTRANS_PULSE_DUR) / BTRANS_PULSE_DUR + game.mosaic = max(1, math.floor(cycle_progress * 16)) return balthasar.update() - if controls.is_control_pressed(4): # DEBUG: battle + if controls.is_control_pressed(4): # DEBUG: battle start_battle(0) if controls.is_control_pressed(0): # Fel @@ -57,24 +58,51 @@ def update(game, dt): elif controls.is_control_pressed(3): # Jobb balthasar.set_direction(DIR_RIGHT) - walking = False + # Calculate movement delta based on input + dx = 0 + dy = 0 + walking = False - if controls.is_control_held(0): # Fel - overworld.scroll_y -= WALK_SPEED * dt + if controls.is_control_held(0): # Fel (Up) + dy += WALK_SPEED * dt walking = True - elif controls.is_control_held(1): # Le - overworld.scroll_y += WALK_SPEED * dt + elif controls.is_control_held(1): # Le (Down) + dy -= WALK_SPEED * dt walking = True - if controls.is_control_held(2): # Bal - overworld.scroll_x += WALK_SPEED * dt + if controls.is_control_held(2): # Bal (Left) + dx -= WALK_SPEED * dt walking = True - elif controls.is_control_held(3): # Jobb - overworld.scroll_x -= WALK_SPEED * dt + elif controls.is_control_held(3): # Jobb (Right) + dx += WALK_SPEED * dt walking = True - + balthasar.set_walking(walking) + if walking: + # Get current world position + cur_x, cur_y = overworld.get_player_world_pos(game) + + # Define collision box dimensions for Balthasar (e.g., 12 width, 10 height at feet) + box_w = 12 + box_h = 10 + + # Test and apply X movement independently (Slide on walls) + if dx != 0: + next_x = cur_x + dx + if overworld.is_box_walkable(next_x, cur_y, box_w, box_h): + overworld.scroll_x -= dx # Note: scroll moves inverse to world pos change + + # Re-fetch current world pos after potential X movement update + cur_x, cur_y = overworld.get_player_world_pos(game) + + # Test and apply Y movement independently + if dy != 0: + next_y = cur_y + dy + if overworld.is_box_walkable(cur_x, next_y, box_w, box_h): + overworld.scroll_y -= dy # Note: scroll moves inverse to world pos change +# !!! CHATGPT VÉGE !!! + def draw(game): overworld.render(game) balthasar.render(game) diff --git a/src/objects.py b/src/objects.py index 5dee8e6..c9d005c 100644 --- a/src/objects.py +++ b/src/objects.py @@ -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: