From 045ad54c5769d5833f5a99bab5e2395d298ddd35 Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 2 Jun 2023 14:54:11 -0700 Subject: [PATCH] Fixed up arena ladders - from Cooliokid956[4~ --- mods/arena/arena-ladder.lua | 41 ++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/mods/arena/arena-ladder.lua b/mods/arena/arena-ladder.lua index a7022c60..e6ca8d27 100644 --- a/mods/arena/arena-ladder.lua +++ b/mods/arena/arena-ladder.lua @@ -7,27 +7,37 @@ ACT_LADDER = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR) -- object yaw = ladder yaw local sLadderClimb = 0 +local ladders = {} ---@param obj Object function bhv_arena_ladder_init(obj) obj.hitboxRadius = 40 obj.hitboxHeight = obj.oBehParams + table.insert(ladders, obj) end id_bhvArenaLadder = hook_behavior(nil, OBJ_LIST_LEVEL, true, bhv_arena_ladder_init, nil) ---@param m MarioState function mario_check_for_ladder(m) - local ladder = obj_get_nearest_object_with_behavior_id(m.marioObj, id_bhvArenaLadder) - if ladder == nil then return end - if m.action & ACT_FLAG_ATTACKING ~= 0 and lateral_dist_between_objects(m.marioObj, ladder) < ladder.hitboxRadius + m.marioObj.hitboxRadius and m.pos.y < ladder.oPosY + ladder.hitboxHeight and m.pos.y + m.marioObj.hitboxHeight > ladder.oPosY then - set_mario_action(m, ACT_LADDER, 0) - gMarioStateExtras[m.playerIndex].ladder = ladder + if not (m.action & ACT_FLAG_ATTACKING ~= 0) or #ladders == 0 then return end + for i, ladder in pairs(ladders) do + if lateral_dist_between_objects(m.marioObj, ladder) < ladder.hitboxRadius + m.marioObj.hitboxRadius and m.pos.y < ladder.oPosY + ladder.hitboxHeight and m.pos.y + m.marioObj.hitboxHeight > ladder.oPosY then + gMarioStateExtras[m.playerIndex].ladder = ladder + set_mario_action(m, ACT_LADDER, 0) + end end end ---@param m MarioState function act_ladder(m) + if gMarioStateExtras[m.playerIndex].ladder == nil then + for i, ladder in pairs(ladders) do + if lateral_dist_between_objects(m.marioObj, ladder) < ladder.hitboxRadius + m.marioObj.hitboxRadius and m.pos.y < ladder.oPosY + ladder.hitboxHeight and m.pos.y + m.marioObj.hitboxHeight > ladder.oPosY then + gMarioStateExtras[m.playerIndex].ladder = ladder + end + end + end local ladder = gMarioStateExtras[m.playerIndex].ladder m.vel.x = 0 @@ -54,19 +64,22 @@ function act_ladder(m) if m.pos.y < ladder.oPosY then m.pos.y = ladder.oPosY end - if m.pos.y > ladder.oPosY or m.pos.y < ladder.oPosY + ladder.hitboxHeight then - sLadderClimb = sLadderClimb + math.abs(m.controller.rawStickY * 0.2) - end - if sLadderClimb > 128 then - sLadderClimb = 0 - play_sound(SOUND_GENERAL_METAL_POUND, m.marioObj.header.gfx.cameraToObject) - end - if (m.input & (INPUT_A_PRESSED | INPUT_B_PRESSED)) ~= 0 then set_mario_action(m,ACT_FREEFALL,0) m.vel.y = m.controller.rawStickY * 0.2 gMarioStateExtras[m.playerIndex].ladder = nil end + if m.playerIndex ~= 0 then return end + if ladder.oPosY < m.pos.y and m.pos.y < ladder.oPosY + ladder.hitboxHeight then + sLadderClimb = sLadderClimb + math.abs(m.controller.rawStickY * 0.2) + end + if sLadderClimb > 128 and m.playerIndex == 0 then + sLadderClimb = 0 + play_sound(SOUND_GENERAL_METAL_POUND, m.marioObj.header.gfx.cameraToObject) + end end - +function clearladders() + ladders = {} +end +hook_event(HOOK_ON_LEVEL_INIT,clearladders) hook_mario_action(ACT_LADDER, { every_frame = act_ladder })