objektum interakció
This commit is contained in:
@@ -21,6 +21,11 @@ btrans_sound = None
|
|||||||
BTRANS_PULSE_DUR = 0.25
|
BTRANS_PULSE_DUR = 0.25
|
||||||
BTRANS_DURATION = 0.75
|
BTRANS_DURATION = 0.75
|
||||||
|
|
||||||
|
# !!! CHATGPT !!!
|
||||||
|
INTERACT_DISTANCE = 10
|
||||||
|
INTERACT_WIDTH = 10
|
||||||
|
INTERACT_HEIGHT = 10
|
||||||
|
|
||||||
def aabb_check(left1, bottom1, right1, top1,
|
def aabb_check(left1, bottom1, right1, top1,
|
||||||
left2, bottom2, right2, top2):
|
left2, bottom2, right2, top2):
|
||||||
return (
|
return (
|
||||||
@@ -30,6 +35,33 @@ def aabb_check(left1, bottom1, right1, top1,
|
|||||||
top1 > bottom2
|
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):
|
def get_feet_aabb(world_x, world_y, width, height):
|
||||||
"""Returns the world-space AABB of the feet collision box."""
|
"""Returns the world-space AABB of the feet collision box."""
|
||||||
feet_offset_y = (B_SPRITE_HEIGHT - height) / 2
|
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
|
top = box_center_y + (height / 2) - 1
|
||||||
|
|
||||||
return left, bottom, right, top
|
return left, bottom, right, top
|
||||||
|
# !!! CHATGPT VÉGE !!!
|
||||||
|
|
||||||
def start_battle(battle_id):
|
def start_battle(battle_id):
|
||||||
global btrans_active, btrans_timer, btrans_sound
|
global btrans_active, btrans_timer, btrans_sound
|
||||||
@@ -71,9 +103,15 @@ def update(game, dt):
|
|||||||
return
|
return
|
||||||
|
|
||||||
balthasar.update()
|
balthasar.update()
|
||||||
|
cur_x, cur_y = overworld.get_player_world_pos(game)
|
||||||
|
balthasar.y = cur_y
|
||||||
|
|
||||||
if controls.is_control_pressed(4): # DEBUG: battle
|
if controls.is_control_pressed(4): # interakció
|
||||||
start_battle(0)
|
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
|
if controls.is_control_pressed(0): # Fel
|
||||||
balthasar.set_direction(DIR_UP)
|
balthasar.set_direction(DIR_UP)
|
||||||
@@ -104,8 +142,7 @@ def update(game, dt):
|
|||||||
walking = True
|
walking = True
|
||||||
|
|
||||||
balthasar.set_walking(walking)
|
balthasar.set_walking(walking)
|
||||||
cur_x, cur_y = overworld.get_player_world_pos(game)
|
|
||||||
balthasar.y = cur_y
|
|
||||||
|
|
||||||
if walking:
|
if walking:
|
||||||
box_w = 12
|
box_w = 12
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import assets
|
import assets
|
||||||
import arcade
|
import arcade
|
||||||
|
|
||||||
# Main character(balthasar) renderer
|
# Main character renderer
|
||||||
DIR_DOWN = 0
|
DIR_DOWN = 0
|
||||||
DIR_UP = 1
|
DIR_UP = 1
|
||||||
DIR_RIGHT = 2
|
DIR_RIGHT = 2
|
||||||
@@ -17,6 +17,7 @@ class BalthasarRenderer:
|
|||||||
self.direction = DIR_UP
|
self.direction = DIR_UP
|
||||||
self.walking = False
|
self.walking = False
|
||||||
self.anim_timer = 0
|
self.anim_timer = 0
|
||||||
|
self.interactive = False
|
||||||
self.x = 0
|
self.x = 0
|
||||||
self.y = 0
|
self.y = 0
|
||||||
self.w = B_SPRITE_WIDHT
|
self.w = B_SPRITE_WIDHT
|
||||||
@@ -51,7 +52,6 @@ class BalthasarRenderer:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Overworld Map
|
# Overworld Map
|
||||||
|
|
||||||
OVERWORLD_LB_X = 0
|
OVERWORLD_LB_X = 0
|
||||||
OVERWORLD_LB_Y = 0
|
OVERWORLD_LB_Y = 0
|
||||||
OVERWORLD_TILE_WIDTH = 16
|
OVERWORLD_TILE_WIDTH = 16
|
||||||
@@ -153,13 +153,13 @@ class OverworldMap:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Teszt objektum
|
# Teszt objektum
|
||||||
|
|
||||||
class TestObject:
|
class TestObject:
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.w = 16
|
self.w = 16
|
||||||
self.h = 16
|
self.h = 16
|
||||||
|
self.interactive = True
|
||||||
|
|
||||||
def get_aabb(self):
|
def get_aabb(self):
|
||||||
return self.x, self.y, self.x + self.w, self.y + self.h
|
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.LBWH(self.x, self.y, 16, 16).move(*translation),
|
||||||
arcade.color.PURPLE,
|
arcade.color.PURPLE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def on_interact(self, start_battle_func):
|
||||||
|
print("never gonna give you up")
|
||||||
|
start_battle_func(0)
|
||||||
Reference in New Issue
Block a user