Overworld objektumok

This commit is contained in:
markojozsef
2026-10-14 12:38:05 +02:00
parent ba46430a4e
commit 88c1ed0f0c
2 changed files with 90 additions and 25 deletions

View File

@@ -17,6 +17,10 @@ class BalthasarRenderer:
self.direction = DIR_UP
self.walking = False
self.anim_timer = 0
self.x = 0
self.y = 0
self.w = B_SPRITE_WIDHT
self.h = B_SPRITE_HEIGHT
def set_direction(self, direction):
self.direction = direction
@@ -26,12 +30,15 @@ class BalthasarRenderer:
if walking == False:
self.anim_timer = 0
def get_aabb(self):
return 0, 0, 0, 0
def update(self):
self.anim_timer += 1
if self.anim_timer > 30:
self.anim_timer = 0
def render(self, game):
def render(self, game, _):
sprite_h = self.direction if self.direction < 3 else 2
sprite_v = 1 if (self.walking and self.anim_timer <= 15) else 0
flip_h = self.direction == DIR_LEFT
@@ -106,22 +113,15 @@ class OverworldMap:
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):
def is_box_walkable(self, left, bottom, right, top):
"""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)
(right, top),
]
for cx, cy in corners:
@@ -129,23 +129,43 @@ class OverworldMap:
tile_y = int(cy // OVERWORLD_TILE_HEIGHT)
# Check map bounds
if not (0 <= tile_x < OVERWORLD_WIDTH and 0 <= tile_y < OVERWORLD_HEIGHT):
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 get_translation(self, game):
return (
self.scroll_x + (game.screen_width / 2) - ((OVERWORLD_WIDTH * OVERWORLD_TILE_WIDTH) / 2),
self.scroll_y + (game.screen_height / 2) - ((OVERWORLD_HEIGHT * OVERWORLD_TILE_HEIGHT) / 2)
)
def render(self, game):
for s in self.sprites:
arcade.draw_texture_rect(
s[0],
s[1].move(
self.scroll_x + (game.screen_width / 2) - ((OVERWORLD_WIDTH * OVERWORLD_TILE_WIDTH) / 2),
self.scroll_y + (game.screen_height / 2) - ((OVERWORLD_HEIGHT * OVERWORLD_TILE_HEIGHT) / 2)
),
s[1].move(*self.get_translation(game)),
pixelated=True
)
# Teszt objektum
class TestObject:
def __init__(self, x, y):
self.x = x
self.y = y
self.w = 16
self.h = 16
def get_aabb(self):
return self.x, self.y, self.x + self.w, self.y + self.h
def render(self, game, translation):
arcade.draw_rect_filled(
arcade.LBWH(self.x, self.y, 16, 16).move(*translation),
arcade.color.PURPLE,
)