Overworld dizájn
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user