objektum interakció
This commit is contained in:
@@ -21,6 +21,11 @@ btrans_sound = None
|
||||
BTRANS_PULSE_DUR = 0.25
|
||||
BTRANS_DURATION = 0.75
|
||||
|
||||
# !!! CHATGPT !!!
|
||||
INTERACT_DISTANCE = 10
|
||||
INTERACT_WIDTH = 10
|
||||
INTERACT_HEIGHT = 10
|
||||
|
||||
def aabb_check(left1, bottom1, right1, top1,
|
||||
left2, bottom2, right2, top2):
|
||||
return (
|
||||
@@ -30,6 +35,33 @@ def aabb_check(left1, bottom1, right1, top1,
|
||||
top1 > bottom2
|
||||
)
|
||||
|
||||
|
||||
def get_interaction_aabb(world_x, world_y, direction):
|
||||
left, bottom, right, top = get_feet_aabb(
|
||||
world_x,
|
||||
world_y,
|
||||
INTERACT_WIDTH,
|
||||
INTERACT_HEIGHT
|
||||
)
|
||||
|
||||
if direction == DIR_UP:
|
||||
bottom += INTERACT_DISTANCE
|
||||
top += INTERACT_DISTANCE
|
||||
|
||||
elif direction == DIR_DOWN:
|
||||
bottom -= INTERACT_DISTANCE
|
||||
top -= INTERACT_DISTANCE
|
||||
|
||||
elif direction == DIR_LEFT:
|
||||
left -= INTERACT_DISTANCE
|
||||
right -= INTERACT_DISTANCE
|
||||
|
||||
elif direction == DIR_RIGHT:
|
||||
left += INTERACT_DISTANCE
|
||||
right += INTERACT_DISTANCE
|
||||
|
||||
return left, bottom, right, top
|
||||
|
||||
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
|
||||
@@ -41,7 +73,7 @@ def get_feet_aabb(world_x, world_y, width, height):
|
||||
top = box_center_y + (height / 2) - 1
|
||||
|
||||
return left, bottom, right, top
|
||||
|
||||
# !!! CHATGPT VÉGE !!!
|
||||
|
||||
def start_battle(battle_id):
|
||||
global btrans_active, btrans_timer, btrans_sound
|
||||
@@ -71,9 +103,15 @@ def update(game, dt):
|
||||
return
|
||||
|
||||
balthasar.update()
|
||||
cur_x, cur_y = overworld.get_player_world_pos(game)
|
||||
balthasar.y = cur_y
|
||||
|
||||
if controls.is_control_pressed(4): # DEBUG: battle
|
||||
start_battle(0)
|
||||
if controls.is_control_pressed(4): # interakció
|
||||
int_aabb = get_interaction_aabb(cur_x, cur_y, balthasar.direction)
|
||||
|
||||
for o in objects:
|
||||
if o.interactive and aabb_check(*int_aabb, *o.get_aabb()):
|
||||
o.on_interact(start_battle)
|
||||
|
||||
if controls.is_control_pressed(0): # Fel
|
||||
balthasar.set_direction(DIR_UP)
|
||||
@@ -104,8 +142,7 @@ 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:
|
||||
box_w = 12
|
||||
|
||||
Reference in New Issue
Block a user