From 8a87439884c97e0ec9f72ada3405cc48dcd642fd Mon Sep 17 00:00:00 2001 From: markojozsef Date: Sat, 17 Oct 2026 11:32:02 +0200 Subject: [PATCH] =?UTF-8?q?Overworld=20diz=C3=A1jn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gamestates/overworld.py | 11 ++++----- src/objects.py | 45 +++++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/gamestates/overworld.py b/src/gamestates/overworld.py index 7e138fc..b42a32b 100644 --- a/src/gamestates/overworld.py +++ b/src/gamestates/overworld.py @@ -8,13 +8,13 @@ from objects import BalthasarRenderer, OverworldMap, BattlePodium, DIR_UP, DIR_L WALK_SPEED = 48 -balthasar = BalthasarRenderer() +balthasar = BalthasarRenderer(96,16) overworld = OverworldMap() objects = [ - BattlePodium(0 , 0, 0), - BattlePodium(96, 0, 1), - BattlePodium(0 ,96, 2), - BattlePodium(96,96, 3), + BattlePodium( 72, 32, 0), + BattlePodium( 32, 72, 1), + BattlePodium(112, 72, 2), + BattlePodium( 72, 112, 3), balthasar ] @@ -87,6 +87,7 @@ def start_battle(battle_id): def switch(game): in_battle_transition = False + overworld.set_player_world_pos(game, balthasar.x, balthasar.y) # !!! CHATGPT !!! def update(game, dt): diff --git a/src/objects.py b/src/objects.py index 892d276..6f90d42 100644 --- a/src/objects.py +++ b/src/objects.py @@ -13,13 +13,13 @@ B_SPRITE_WALKING = 3 class BalthasarRenderer: - def __init__(self): + def __init__(self, x, y): self.direction = DIR_UP self.walking = False self.anim_timer = 0 self.interactive = False - self.x = 0 - self.y = 0 + self.x = x + self.y = y self.w = B_SPRITE_WIDHT self.h = B_SPRITE_HEIGHT @@ -56,17 +56,21 @@ OVERWORLD_LB_X = 0 OVERWORLD_LB_Y = 0 OVERWORLD_TILE_WIDTH = 16 OVERWORLD_TILE_HEIGHT = 16 -OVERWORLD_WIDTH = 8 -OVERWORLD_HEIGHT = 8 +OVERWORLD_WIDTH = 12 +OVERWORLD_HEIGHT = 12 OVERWORLD_MAP = [ - [5,3,3,3,3,3,3,6], - [1,0,0,0,0,0,0,2], - [1,0,0,0,0,0,0,2], - [1,0,0,0,0,0,0,2], - [1,0,0,0,0,0,0,2], - [1,0,0,0,0,0,0,2], - [1,0,0,0,0,0,0,2], - [7,4,4,4,4,4,4,8], + [9, 9, 9, 5, 3, 3, 3, 3, 6, 9, 9, 9], + [9, 9, 5, 0, 0, 0, 0, 0, 0, 6, 9, 9], + [9, 5, 0, 0, 0, 0, 0, 0, 0, 0, 6, 9], + [5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6], + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], + [7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8], + [9, 7, 0, 0, 0, 0, 0, 0, 0, 0, 8, 9], + [9, 9, 7, 0, 0, 0, 0, 0, 0, 8, 9, 9], + [9, 9, 9, 7, 4, 4, 4, 4, 8, 9, 9, 9], ] class OverworldMap: @@ -107,6 +111,15 @@ class OverworldMap: return player_world_x, player_world_y + def set_player_world_pos(self, game, target_x, target_y): + """Sets the player's world position by adjusting the scroll offsets.""" + half_world_width = (OVERWORLD_WIDTH * OVERWORLD_TILE_WIDTH) / 2 + half_world_height = (OVERWORLD_HEIGHT * OVERWORLD_TILE_HEIGHT) / 2 + + # Reverse the math from get_player_world_pos to solve for scroll_x and scroll_y + self.scroll_x = half_world_width - target_x + self.scroll_y = half_world_height - target_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) @@ -138,7 +151,11 @@ class OverworldMap: 0 <= tile_y < OVERWORLD_HEIGHT ): return False # Out of bounds is a wall - + + tile_id = OVERWORLD_MAP[OVERWORLD_HEIGHT - 1 - tile_y][tile_x] + + if tile_id > 8: + return False return True