Arena tweaks (#58)

noticed that a recent commit broke ladders, so i took this opportunity to bring some things up to date

- upgraded the ladder system to more or less its current state in Dream Raider 64
- lowered streamed music volume when paused
- cap music plays where it's supposed to again
- other cleanup in the sound system
This commit is contained in:
Cooliokid956 2024-06-05 16:10:37 -05:00 committed by GitHub
parent 4592559fe3
commit 36ddaa65ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 136 additions and 156 deletions

View file

@ -1,112 +1,92 @@
_G.ACT_LADDER = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR)
-- behavior params: -- behavior params:
-- ladder height -- ladder height
-- ex: 1388 -- ex: 1388
-- object yaw = ladder yaw -- object yaw = ladder yaw
local sLadderClimb = 0 function bhv_arena_ladder_init(o)
local ladders = {} o.hitboxRadius = 40
o.hitboxHeight = o.oBehParams
gPlayerSyncTable[0].ladder = {}
gPlayerSyncTable[0].ladder.x = nil
gPlayerSyncTable[0].ladder.y = nil
gPlayerSyncTable[0].ladder.z = nil
gPlayerSyncTable[0].ladder.height = nil
gPlayerSyncTable[0].ladder.angle = nil
---@param obj Object
function bhv_arena_ladder_init(obj)
obj.hitboxRadius = 40
obj.hitboxHeight = obj.oBehParams
table.insert(ladders, obj)
end end
id_bhvArenaLadder = hook_behavior(nil, OBJ_LIST_LEVEL, true, bhv_arena_ladder_init, nil) id_bhvArenaLadder = hook_behavior(nil, OBJ_LIST_LEVEL, true, bhv_arena_ladder_init, nil)
---@param m MarioState
function mario_check_for_ladder(m) function mario_check_for_ladder(m)
if m.action == ACT_FORWARD_ROLLOUT and m.prevAction == ACT_LADDER then if m.action == ACT_FORWARD_ROLLOUT and m.prevAction == ACT_LADDER then
m.forwardVel = 10 m.forwardVel = 10
end end
if not (m.action & ACT_FLAG_ATTACKING ~= 0) or #ladders == 0 or m.action == ACT_LADDER then return end
for i, ladder in pairs(ladders) do local ladder = obj_get_first_with_behavior_id(id_bhvArenaLadder)
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 while ladder do
gPlayerSyncTable[m.playerIndex].ladder.x = ladder.oPosX if obj_check_hitbox_overlap(m.marioObj, ladder) ~= 0 then
gPlayerSyncTable[m.playerIndex].ladder.y = ladder.oPosY local dYawToObject = ladder.oFaceAngleYaw - m.faceAngle.y
gPlayerSyncTable[m.playerIndex].ladder.z = ladder.oPosZ if ((m.action & ACT_FLAG_AIR ~= 0 and m.forwardVel > 20)
gPlayerSyncTable[m.playerIndex].ladder.height = ladder.hitboxHeight or (m.action & ACT_FLAG_ATTACKING ~= 0 and (m.action ~= ACT_GROUND_POUND or m.action ~= ACT_GROUND_POUND_LAND))
gPlayerSyncTable[m.playerIndex].ladder.angle = ladder.oFaceAngleYaw or (m.action & ACT_FLAG_AIR == 0 and m.input & INPUT_A_PRESSED ~= 0)
set_mario_action(m, ACT_LADDER, 0) ) and math.abs(dYawToObject) < 0x2000 and m.action ~= ACT_LADDER then
m.usedObj = ladder
m.input = m.input & ~INPUT_A_PRESSED
return set_mario_action(m, ACT_LADDER, 0)
end end
end end
ladder = obj_get_next_with_same_behavior_id(ladder)
end
end end
hook_event(HOOK_BEFORE_MARIO_UPDATE, mario_check_for_ladder)
---@param m MarioState
function act_ladder(m) function act_ladder(m)
local ladder = gPlayerSyncTable[m.playerIndex].ladder local ladder = m.usedObj
local x = m.controller.rawStickX if not ladder or obj_has_behavior_id(ladder, id_bhvArenaLadder) == 0 then return set_mario_action(m, ACT_FREEFALL, 0) end
local y = m.controller.rawStickY
m.vel.x = 0 local stickX = m.controller.rawStickX
m.vel.y = 0 local stickY = m.controller.rawStickY
m.vel.z = 0
m.forwardVel = 0
perform_air_step(m, 0) m.vel.x = ladder.oPosX
m.vel.z = ladder.oPosZ
m.vel.y = clampf(m.pos.y + stickY*.15, ladder.oPosY, ladder.oPosY + ladder.hitboxHeight)
m.pos.x = ladder.x vec3f_copy(m.marioObj.header.gfx.pos, m.pos)
m.pos.z = ladder.z
set_mario_animation(m, MARIO_ANIM_BEING_GRABBED) set_character_animation(m, CHAR_ANIM_BEING_GRABBED)
local loop = m.marioObj.header.gfx.animInfo.curAnim.loopEnd local loop = m.marioObj.header.gfx.animInfo.curAnim.loopEnd
set_anim_to_frame(m, m.pos.y/10 - math.floor(m.pos.y / 10 / loop) * loop) set_anim_to_frame(m, (m.pos.y/10) % loop)
m.marioObj.header.gfx.angle.x = 8192 m.faceAngle.x = 8192
m.faceAngle.y = ladder.angle m.faceAngle.y = ladder.oFaceAngleYaw
m.faceAngle.z = 0
vec3s_copy(m.marioObj.header.gfx.angle, m.faceAngle)
m.pos.y = m.pos.y + y*.2
if m.pos.y > ladder.y + ladder.height then
m.pos.y = ladder.y + ladder.height
end
if m.pos.y < ladder.y then
m.pos.y = ladder.y
end
if m.input & INPUT_A_PRESSED ~= 0 then if m.input & INPUT_A_PRESSED ~= 0 then
if math.abs(m.controller.rawStickX) > 64 then if math.abs(stickX) > 64 then
set_mario_action(m,ACT_FORWARD_ROLLOUT,0) m.faceAngle.y = m.faceAngle.y - 16384*signum_positive(stickX)
m.faceAngle.y = m.faceAngle.y - 16384*math.abs(x)/x
m.forwardVel = 10 m.forwardVel = 10
m.vel.y = 10 m.vel.y = 10
return return set_mario_action(m, ACT_FORWARD_ROLLOUT, 0)
end end
if m.controller.rawStickY > 64 then if stickY > 64 and m.pos.y == ladder.oPosY + ladder.hitboxHeight then
set_mario_action(m,ACT_FORWARD_ROLLOUT,0)
m.forwardVel = 10 m.forwardVel = 10
m.vel.y = 10 m.vel.y = 10
return return set_mario_action(m, ACT_FORWARD_ROLLOUT, 0)
end end
set_mario_action(m,ACT_WALL_KICK_AIR,0)
m.faceAngle.y = m.faceAngle.y + 32768 m.faceAngle.y = m.faceAngle.y + 32768
m.forwardVel = 30 m.forwardVel = 30
m.vel.y = 50 m.vel.y = 50
return return set_mario_action(m, ACT_WALL_KICK_AIR, 0)
end end
if m.input & INPUT_Z_PRESSED ~= 0 then if m.input & INPUT_Z_PRESSED ~= 0 then
set_mario_action(m,ACT_FREEFALL,0) m.vel.y = stickY * 0.2
m.vel.y = y * 0.2 m.forwardVel = 0
return m.input = m.input & ~INPUT_Z_PRESSED
return set_mario_action(m, ACT_FREEFALL, 0)
end end
if m.playerIndex ~= 0 then return end if ladder.oPosY < m.pos.y and m.pos.y < ladder.oPosY + ladder.hitboxHeight then
if ladder.y < m.pos.y and m.pos.y < ladder.y + ladder.height then m.actionTimer = m.actionTimer + math.abs(stickY * 0.2)
sLadderClimb = sLadderClimb + math.abs(y * 0.2)
end end
if sLadderClimb > 128 and m.playerIndex == 0 then if m.actionTimer > 128 then
sLadderClimb = 0 m.actionTimer = 0
play_sound(SOUND_GENERAL_METAL_POUND, m.marioObj.header.gfx.cameraToObject) play_sound(SOUND_GENERAL_METAL_POUND, m.marioObj.header.gfx.cameraToObject)
end end
end end
function clearladders() hook_mario_action(ACT_LADDER, act_ladder)
ladders = {}
end
hook_event(HOOK_ON_LEVEL_INIT,clearladders)
hook_mario_action(ACT_LADDER, { every_frame = act_ladder })

View file

@ -402,9 +402,6 @@ function mario_local_update(m)
end end
end end
-- check for ladder
mario_check_for_ladder(m)
e.prevHurtCounter = m.hurtCounter e.prevHurtCounter = m.hurtCounter
end end

View file

@ -1,25 +1,27 @@
local m = gMarioStates[0]
local np = gNetworkPlayers[0]
local pauseMenuShouldShowMusic = true local pauseMenuShouldShowMusic = true
local pauseMenuMusicRGBA = {200,200,200,255} local pauseMenuShowLevelID = true
local pauseMenuShowLevelID = false
local curMap = -1 local curMap = -1
local audioMainPaused = false local audioMainPaused = false
local audioMain = nil --Used for the main audio local audioMain --Used for the main audio
local audioSpecial = nil --Used for things like cap music local audioSpecial --Used for things like cap music
local audioCurSeq = nil local audioCurSeq
local bgms = { local bgms = {
[55] = {audio='snow.ogg', loopEnd = 500, loopStart = 0, volume = -5, name="Frosty Citadel - Sonic Gaiden" }, -- Spire [55] = {audio='snow.ogg', loopEnd = 500, loopStart = 0, volume = 1, name="Frosty Citadel - Sonic Gaiden" },
[56] = {audio='rainbow.ogg', loopEnd = 148.657, loopStart = 12.406, volume = -5, name="Rainbow Road - Coop Deluxe" }, -- Rainbow [56] = {audio='rainbow.ogg', loopEnd = 148.657, loopStart = 12.406, volume = 1, name="Rainbow Road - Coop Deluxe" },
[57] = {audio='city.ogg', loopEnd = 500, loopStart = 06.975, volume = -5, name="City Outskirts - Sonic Megamix" } -- City [57] = {audio='city.ogg', loopEnd = 500, loopStart = 06.975, volume = 1, name="City Outskirts - Sonic Megamix" }
} }
-- disable cap music -- disable cap music
function music() function music()
local np = gNetworkPlayers[0] if bgms[np.currLevelNum] then
if np.currLevelNum == LEVEL_ARENA_RAINBOW or LEVEL_ARENA_CITY or LEVEL_ARENA_ORIGIN or LEVEL_ARENA_FORTS or LEVEL_ARENA_SPIRE or LEVEL_ARENA_CITADEL then
stop_cap_music() stop_cap_music()
end end
end end
hook_event(HOOK_UPDATE, music) hook_event(HOOK_UPDATE, music)
function handleMusic() function handleMusic()
@ -27,20 +29,20 @@ function handleMusic()
-- Handle stopping/starting of music -- -- Handle stopping/starting of music --
------------------------------------------------------ ------------------------------------------------------
--Handle main course music --Handle main course music
if (curMap ~= gNetworkPlayers[0].currLevelNum and gMarioStates[0].area.macroObjects ~= nil) then if curMap ~= np.currLevelNum and m.area.macroObjects then
curMap = gNetworkPlayers[0].currLevelNum curMap = np.currLevelNum
audioCurSeq = get_current_background_music() audioCurSeq = get_current_background_music()
if (audioMain ~= nil) then if audioMain then
audio_stream_stop(audioMain) audio_stream_stop(audioMain)
audio_stream_destroy(audioMain) audio_stream_destroy(audioMain)
audioMain = nil audioMain = nil
end end
if (bgms[curMap] ~= nil and bgms[curMap].audio ~= nil) then if bgms[curMap] and bgms[curMap].audio then
set_background_music(0,0,0) set_background_music(0,0,0)
audioMain = audio_stream_load(bgms[curMap].audio) audioMain = audio_stream_load(bgms[curMap].audio)
if (audioMain ~= nil) then if audioMain then
audio_stream_set_looping(audioMain, true) audio_stream_set_looping(audioMain, true)
audio_stream_play(audioMain, true, bgms[curMap].volume); audio_stream_play(audioMain, true, bgms[curMap].volume)
print("Playing new audio " .. bgms[curMap].name) print("Playing new audio " .. bgms[curMap].name)
else else
djui_popup_create('Missing audio!: ' .. bgms[curMap].audio, 10) djui_popup_create('Missing audio!: ' .. bgms[curMap].audio, 10)
@ -51,18 +53,18 @@ function handleMusic()
end end
end end
--Handle cap music --Handle cap music
if (gMarioStates[0].capTimer > 0 and bgms[-2] ~= nil) then if m.capTimer > 0 and bgms[-2] then
--Handle pausing main streamed music, if applicable. --Handle pausing main streamed music, if applicable.
if (audioMain ~= nil and audioMainPaused == false) then if audioMain and not audioMainPaused then
audioMainPaused = true audioMainPaused = true
audio_stream_pause(audioMain) audio_stream_pause(audioMain)
end end
--Start up cap music if it's defined. --Start up cap music if it's defined.
if (audioSpecial == nil) then if not audioSpecial then
set_background_music(0,0,0) set_background_music(0,0,0)
stop_cap_music() stop_cap_music()
audioSpecial = audio_stream_load(bgms[-2].audio) audioSpecial = audio_stream_load(bgms[-2].audio)
if (audioSpecial ~= nil) then if audioSpecial then
audio_stream_set_looping(audioSpecial, true) audio_stream_set_looping(audioSpecial, true)
audio_stream_play(audioSpecial, true, bgms[-2].volume) audio_stream_play(audioSpecial, true, bgms[-2].volume)
print("Playing cap audio " .. bgms[-2].name) print("Playing cap audio " .. bgms[-2].name)
@ -72,30 +74,31 @@ function handleMusic()
end end
end end
else else
if (audioSpecial ~= nil) then if audioSpecial then
audio_stream_stop(audioSpecial) audio_stream_stop(audioSpecial)
audio_stream_destroy(audioSpecial) audio_stream_destroy(audioSpecial)
audioSpecial = nil audioSpecial = nil
if (audioMain ~= nil and audioMainPaused == true) then if audioMain and audioMainPaused then
audioMainPaused = false audioMainPaused = false
audio_stream_play(audioMain, false, bgms[curMap].volume) audio_stream_play(audioMain, false, bgms[curMap].volume)
else else
set_background_music(0, audioCurSeq, 10) set_background_music(0, audioCurSeq, 10)
end end
end end
end end
if (audioMain ~= nil) then if audioMain then
audio_stream_set_volume(audioMain, is_game_paused() and bgms[curMap].volume/3.5 or bgms[curMap].volume)
local curPosition = audio_stream_get_position(audioMain) local curPosition = audio_stream_get_position(audioMain)
if (curPosition >= bgms[curMap].loopEnd ) then if curPosition >= bgms[curMap].loopEnd then
local minus = bgms[curMap].loopStart - bgms[curMap].loopEnd local minus = bgms[curMap].loopStart - bgms[curMap].loopEnd
audio_stream_set_position(audioMain, curPosition - math.abs(minus)) audio_stream_set_position(audioMain, curPosition - math.abs(minus))
end end
end end
if (audioSpecial ~= nil) then if audioSpecial then
local curPosition = audio_stream_get_position(audioSpecial) local curPosition = audio_stream_get_position(audioSpecial)
if (curPosition >= bgms[-2].loopEnd) then if curPosition >= bgms[-2].loopEnd then
local minus = bgms[-2].loopStart - bgms[-2].loopEnd local minus = bgms[-2].loopStart - bgms[-2].loopEnd
audio_stream_set_position(audioSpecial, curPosition - math.abs(minus)) audio_stream_set_position(audioSpecial, curPosition - math.abs(minus))
end end
@ -103,23 +106,23 @@ function handleMusic()
end end
function hud_render() function hud_render()
if (pauseMenuShouldShowMusic == true and is_game_paused()) then if pauseMenuShouldShowMusic and is_game_paused() then
djui_hud_set_resolution(RESOLUTION_DJUI); djui_hud_set_resolution(RESOLUTION_DJUI)
djui_hud_set_font(FONT_NORMAL); djui_hud_set_font(FONT_NORMAL)
local screenWidth = djui_hud_get_screen_width() local screenWidth = djui_hud_get_screen_width()
local screenHeight = djui_hud_get_screen_height() local screenHeight = djui_hud_get_screen_height()
local height = 64 local height = 64
local y = screenHeight - height local y = screenHeight - height
djui_hud_set_color(pauseMenuMusicRGBA[1], pauseMenuMusicRGBA[2], pauseMenuMusicRGBA[3], pauseMenuMusicRGBA[4]); djui_hud_set_color(200,200,200,255)
local text = ""; local text
if (pauseMenuShowLevelID == true) then if pauseMenuShowLevelID then
text = "Level ID: " .. gNetworkPlayers[0].currLevelNum text = "Level ID: " .. np.currLevelNum
elseif (audioSpecial ~= nil) then elseif audioSpecial then
text = "Music: " .. bgms[-2].name text = "Music: " .. bgms[-2].name
elseif (audioMain ~= nil) then elseif audioMain then
text = "Music: " .. bgms[curMap].name text = "Music: " .. bgms[curMap].name
end end
djui_hud_print_text(text, 5, y, 1); djui_hud_print_text(text, 5, y, 1)
end end
end end
hook_event(HOOK_ON_HUD_RENDER, hud_render) hook_event(HOOK_ON_HUD_RENDER, hud_render)