diff --git a/src/gamestates/overworld.py b/src/gamestates/overworld.py index 80de12b..3aae803 100644 --- a/src/gamestates/overworld.py +++ b/src/gamestates/overworld.py @@ -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 diff --git a/src/objects.py b/src/objects.py index 8225cc2..96883b9 100644 --- a/src/objects.py +++ b/src/objects.py @@ -1,7 +1,7 @@ import assets import arcade -# Main character(balthasar) renderer +# Main character renderer DIR_DOWN = 0 DIR_UP = 1 DIR_RIGHT = 2 @@ -17,6 +17,7 @@ class BalthasarRenderer: self.direction = DIR_UP self.walking = False self.anim_timer = 0 + self.interactive = False self.x = 0 self.y = 0 self.w = B_SPRITE_WIDHT @@ -51,7 +52,6 @@ class BalthasarRenderer: ) # Overworld Map - OVERWORLD_LB_X = 0 OVERWORLD_LB_Y = 0 OVERWORLD_TILE_WIDTH = 16 @@ -153,13 +153,13 @@ class OverworldMap: ) # Teszt objektum - class TestObject: def __init__(self, x, y): self.x = x self.y = y self.w = 16 self.h = 16 + self.interactive = True def get_aabb(self): return self.x, self.y, self.x + self.w, self.y + self.h @@ -169,3 +169,7 @@ class TestObject: arcade.LBWH(self.x, self.y, 16, 16).move(*translation), arcade.color.PURPLE, ) + + def on_interact(self, start_battle_func): + print("never gonna give you up") + start_battle_func(0) \ No newline at end of file