Overworld dizájn
This commit is contained in:
@@ -8,13 +8,13 @@ from objects import BalthasarRenderer, OverworldMap, BattlePodium, DIR_UP, DIR_L
|
|||||||
|
|
||||||
WALK_SPEED = 48
|
WALK_SPEED = 48
|
||||||
|
|
||||||
balthasar = BalthasarRenderer()
|
balthasar = BalthasarRenderer(96,16)
|
||||||
overworld = OverworldMap()
|
overworld = OverworldMap()
|
||||||
objects = [
|
objects = [
|
||||||
BattlePodium(0 , 0, 0),
|
BattlePodium( 72, 32, 0),
|
||||||
BattlePodium(96, 0, 1),
|
BattlePodium( 32, 72, 1),
|
||||||
BattlePodium(0 ,96, 2),
|
BattlePodium(112, 72, 2),
|
||||||
BattlePodium(96,96, 3),
|
BattlePodium( 72, 112, 3),
|
||||||
balthasar
|
balthasar
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -87,6 +87,7 @@ def start_battle(battle_id):
|
|||||||
|
|
||||||
def switch(game):
|
def switch(game):
|
||||||
in_battle_transition = False
|
in_battle_transition = False
|
||||||
|
overworld.set_player_world_pos(game, balthasar.x, balthasar.y)
|
||||||
|
|
||||||
# !!! CHATGPT !!!
|
# !!! CHATGPT !!!
|
||||||
def update(game, dt):
|
def update(game, dt):
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ B_SPRITE_WALKING = 3
|
|||||||
|
|
||||||
|
|
||||||
class BalthasarRenderer:
|
class BalthasarRenderer:
|
||||||
def __init__(self):
|
def __init__(self, x, y):
|
||||||
self.direction = DIR_UP
|
self.direction = DIR_UP
|
||||||
self.walking = False
|
self.walking = False
|
||||||
self.anim_timer = 0
|
self.anim_timer = 0
|
||||||
self.interactive = False
|
self.interactive = False
|
||||||
self.x = 0
|
self.x = x
|
||||||
self.y = 0
|
self.y = y
|
||||||
self.w = B_SPRITE_WIDHT
|
self.w = B_SPRITE_WIDHT
|
||||||
self.h = B_SPRITE_HEIGHT
|
self.h = B_SPRITE_HEIGHT
|
||||||
|
|
||||||
@@ -56,17 +56,21 @@ OVERWORLD_LB_X = 0
|
|||||||
OVERWORLD_LB_Y = 0
|
OVERWORLD_LB_Y = 0
|
||||||
OVERWORLD_TILE_WIDTH = 16
|
OVERWORLD_TILE_WIDTH = 16
|
||||||
OVERWORLD_TILE_HEIGHT = 16
|
OVERWORLD_TILE_HEIGHT = 16
|
||||||
OVERWORLD_WIDTH = 8
|
OVERWORLD_WIDTH = 12
|
||||||
OVERWORLD_HEIGHT = 8
|
OVERWORLD_HEIGHT = 12
|
||||||
OVERWORLD_MAP = [
|
OVERWORLD_MAP = [
|
||||||
[5,3,3,3,3,3,3,6],
|
[9, 9, 9, 5, 3, 3, 3, 3, 6, 9, 9, 9],
|
||||||
[1,0,0,0,0,0,0,2],
|
[9, 9, 5, 0, 0, 0, 0, 0, 0, 6, 9, 9],
|
||||||
[1,0,0,0,0,0,0,2],
|
[9, 5, 0, 0, 0, 0, 0, 0, 0, 0, 6, 9],
|
||||||
[1,0,0,0,0,0,0,2],
|
[5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6],
|
||||||
[1,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,2],
|
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2],
|
||||||
[1,0,0,0,0,0,0,2],
|
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2],
|
||||||
[7,4,4,4,4,4,4,8],
|
[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:
|
class OverworldMap:
|
||||||
@@ -107,6 +111,15 @@ class OverworldMap:
|
|||||||
|
|
||||||
return player_world_x, player_world_y
|
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):
|
def get_tile_at(self, world_x, world_y):
|
||||||
"""Returns the map tile ID at a given world pixel position."""
|
"""Returns the map tile ID at a given world pixel position."""
|
||||||
tile_x = int(world_x // OVERWORLD_TILE_WIDTH)
|
tile_x = int(world_x // OVERWORLD_TILE_WIDTH)
|
||||||
@@ -139,6 +152,10 @@ class OverworldMap:
|
|||||||
):
|
):
|
||||||
return False # Out of bounds is a wall
|
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
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user