Overworld objektumok
This commit is contained in:
@@ -4,12 +4,16 @@ import controls
|
||||
import gamestate
|
||||
import math
|
||||
|
||||
from objects import BalthasarRenderer, OverworldMap, DIR_UP, DIR_LEFT, DIR_DOWN, DIR_RIGHT
|
||||
from objects import BalthasarRenderer, OverworldMap, TestObject, DIR_UP, DIR_LEFT, DIR_DOWN, DIR_RIGHT, B_SPRITE_HEIGHT
|
||||
|
||||
WALK_SPEED = 48
|
||||
|
||||
balthasar = BalthasarRenderer()
|
||||
overworld = OverworldMap()
|
||||
objects = [
|
||||
TestObject(0,16),
|
||||
balthasar
|
||||
]
|
||||
|
||||
btrans_active = False
|
||||
btrans_timer = 0
|
||||
@@ -17,6 +21,28 @@ btrans_sound = None
|
||||
BTRANS_PULSE_DUR = 0.25
|
||||
BTRANS_DURATION = 0.75
|
||||
|
||||
def aabb_check(left1, bottom1, right1, top1,
|
||||
left2, bottom2, right2, top2):
|
||||
return (
|
||||
left1 < right2 and
|
||||
right1 > left2 and
|
||||
bottom1 < top2 and
|
||||
top1 > bottom2
|
||||
)
|
||||
|
||||
def get_feet_aabb(world_x, world_y, width, height):
|
||||
"""Returns the world-space AABB of the feet collision box."""
|
||||
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
|
||||
|
||||
return left, bottom, right, top
|
||||
|
||||
|
||||
def start_battle(battle_id):
|
||||
global btrans_active, btrans_timer, btrans_sound
|
||||
gamestate.gamestates["battle"].battle_id = battle_id
|
||||
@@ -78,19 +104,26 @@ def update(game, dt):
|
||||
walking = True
|
||||
|
||||
balthasar.set_walking(walking)
|
||||
cur_x, cur_y = overworld.get_player_world_pos(game)
|
||||
balthasar.y = cur_y
|
||||
|
||||
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
|
||||
box_h = 14
|
||||
|
||||
# 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):
|
||||
feet_aabb = get_feet_aabb(next_x, cur_y, box_w, box_h)
|
||||
can_move = False
|
||||
if overworld.is_box_walkable(*feet_aabb):
|
||||
can_move = True
|
||||
|
||||
for o in objects:
|
||||
if aabb_check(*feet_aabb, *o.get_aabb()):
|
||||
can_move = False
|
||||
|
||||
if can_move:
|
||||
overworld.scroll_x -= dx # Note: scroll moves inverse to world pos change
|
||||
|
||||
# Re-fetch current world pos after potential X movement update
|
||||
@@ -99,10 +132,22 @@ def update(game, dt):
|
||||
# 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):
|
||||
feet_aabb = get_feet_aabb(cur_x, next_y, box_w, box_h)
|
||||
can_move = False
|
||||
if overworld.is_box_walkable(*feet_aabb):
|
||||
can_move = True
|
||||
|
||||
for o in objects:
|
||||
if aabb_check(*feet_aabb, *o.get_aabb()):
|
||||
can_move = False
|
||||
|
||||
if can_move:
|
||||
overworld.scroll_y -= dy # Note: scroll moves inverse to world pos change
|
||||
# !!! CHATGPT VÉGE !!!
|
||||
|
||||
def draw(game):
|
||||
overworld.render(game)
|
||||
balthasar.render(game)
|
||||
|
||||
trans = overworld.get_translation(game)
|
||||
for o in sorted(objects, key=lambda o: o.y, reverse=True):
|
||||
o.render(game, trans)
|
||||
Reference in New Issue
Block a user