mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-21 19:45:10 +00:00
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:
parent
4592559fe3
commit
36ddaa65ac
3 changed files with 136 additions and 156 deletions
|
@ -1,112 +1,92 @@
|
|||
_G.ACT_LADDER = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR)
|
||||
|
||||
-- behavior params:
|
||||
|
||||
-- ladder height
|
||||
-- ex: 1388
|
||||
-- object yaw = ladder yaw
|
||||
|
||||
local sLadderClimb = 0
|
||||
local ladders = {}
|
||||
|
||||
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)
|
||||
function bhv_arena_ladder_init(o)
|
||||
o.hitboxRadius = 40
|
||||
o.hitboxHeight = o.oBehParams
|
||||
end
|
||||
|
||||
id_bhvArenaLadder = hook_behavior(nil, OBJ_LIST_LEVEL, true, bhv_arena_ladder_init, nil)
|
||||
|
||||
---@param m MarioState
|
||||
function mario_check_for_ladder(m)
|
||||
if m.action == ACT_FORWARD_ROLLOUT and m.prevAction == ACT_LADDER then
|
||||
m.forwardVel = 10
|
||||
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
|
||||
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
|
||||
gPlayerSyncTable[m.playerIndex].ladder.x = ladder.oPosX
|
||||
gPlayerSyncTable[m.playerIndex].ladder.y = ladder.oPosY
|
||||
gPlayerSyncTable[m.playerIndex].ladder.z = ladder.oPosZ
|
||||
gPlayerSyncTable[m.playerIndex].ladder.height = ladder.hitboxHeight
|
||||
gPlayerSyncTable[m.playerIndex].ladder.angle = ladder.oFaceAngleYaw
|
||||
set_mario_action(m, ACT_LADDER, 0)
|
||||
|
||||
local ladder = obj_get_first_with_behavior_id(id_bhvArenaLadder)
|
||||
while ladder do
|
||||
if obj_check_hitbox_overlap(m.marioObj, ladder) ~= 0 then
|
||||
local dYawToObject = ladder.oFaceAngleYaw - m.faceAngle.y
|
||||
if ((m.action & ACT_FLAG_AIR ~= 0 and m.forwardVel > 20)
|
||||
or (m.action & ACT_FLAG_ATTACKING ~= 0 and (m.action ~= ACT_GROUND_POUND or m.action ~= ACT_GROUND_POUND_LAND))
|
||||
or (m.action & ACT_FLAG_AIR == 0 and m.input & INPUT_A_PRESSED ~= 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
|
||||
ladder = obj_get_next_with_same_behavior_id(ladder)
|
||||
end
|
||||
end
|
||||
hook_event(HOOK_BEFORE_MARIO_UPDATE, mario_check_for_ladder)
|
||||
|
||||
---@param m MarioState
|
||||
function act_ladder(m)
|
||||
local ladder = gPlayerSyncTable[m.playerIndex].ladder
|
||||
local x = m.controller.rawStickX
|
||||
local y = m.controller.rawStickY
|
||||
local ladder = m.usedObj
|
||||
if not ladder or obj_has_behavior_id(ladder, id_bhvArenaLadder) == 0 then return set_mario_action(m, ACT_FREEFALL, 0) end
|
||||
|
||||
m.vel.x = 0
|
||||
m.vel.y = 0
|
||||
m.vel.z = 0
|
||||
m.forwardVel = 0
|
||||
local stickX = m.controller.rawStickX
|
||||
local stickY = m.controller.rawStickY
|
||||
|
||||
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
|
||||
m.pos.z = ladder.z
|
||||
vec3f_copy(m.marioObj.header.gfx.pos, m.pos)
|
||||
|
||||
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
|
||||
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.y = ladder.angle
|
||||
m.faceAngle.x = 8192
|
||||
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 math.abs(m.controller.rawStickX) > 64 then
|
||||
set_mario_action(m,ACT_FORWARD_ROLLOUT,0)
|
||||
m.faceAngle.y = m.faceAngle.y - 16384*math.abs(x)/x
|
||||
if math.abs(stickX) > 64 then
|
||||
m.faceAngle.y = m.faceAngle.y - 16384*signum_positive(stickX)
|
||||
m.forwardVel = 10
|
||||
m.vel.y = 10
|
||||
return
|
||||
return set_mario_action(m, ACT_FORWARD_ROLLOUT, 0)
|
||||
end
|
||||
if m.controller.rawStickY > 64 then
|
||||
set_mario_action(m,ACT_FORWARD_ROLLOUT,0)
|
||||
if stickY > 64 and m.pos.y == ladder.oPosY + ladder.hitboxHeight then
|
||||
m.forwardVel = 10
|
||||
m.vel.y = 10
|
||||
return
|
||||
return set_mario_action(m, ACT_FORWARD_ROLLOUT, 0)
|
||||
end
|
||||
set_mario_action(m,ACT_WALL_KICK_AIR,0)
|
||||
m.faceAngle.y = m.faceAngle.y + 32768
|
||||
m.forwardVel = 30
|
||||
m.vel.y = 50
|
||||
return
|
||||
return set_mario_action(m, ACT_WALL_KICK_AIR, 0)
|
||||
end
|
||||
if m.input & INPUT_Z_PRESSED ~= 0 then
|
||||
set_mario_action(m,ACT_FREEFALL,0)
|
||||
m.vel.y = y * 0.2
|
||||
return
|
||||
m.vel.y = stickY * 0.2
|
||||
m.forwardVel = 0
|
||||
m.input = m.input & ~INPUT_Z_PRESSED
|
||||
return set_mario_action(m, ACT_FREEFALL, 0)
|
||||
end
|
||||
if m.playerIndex ~= 0 then return end
|
||||
if ladder.y < m.pos.y and m.pos.y < ladder.y + ladder.height then
|
||||
sLadderClimb = sLadderClimb + math.abs(y * 0.2)
|
||||
if ladder.oPosY < m.pos.y and m.pos.y < ladder.oPosY + ladder.hitboxHeight then
|
||||
m.actionTimer = m.actionTimer + math.abs(stickY * 0.2)
|
||||
end
|
||||
if sLadderClimb > 128 and m.playerIndex == 0 then
|
||||
sLadderClimb = 0
|
||||
if m.actionTimer > 128 then
|
||||
m.actionTimer = 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 })
|
||||
hook_mario_action(ACT_LADDER, act_ladder)
|
||||
|
|
|
@ -402,9 +402,6 @@ function mario_local_update(m)
|
|||
end
|
||||
end
|
||||
|
||||
-- check for ladder
|
||||
mario_check_for_ladder(m)
|
||||
|
||||
e.prevHurtCounter = m.hurtCounter
|
||||
end
|
||||
|
||||
|
|
|
@ -1,46 +1,48 @@
|
|||
local m = gMarioStates[0]
|
||||
local np = gNetworkPlayers[0]
|
||||
|
||||
local pauseMenuShouldShowMusic = true
|
||||
local pauseMenuMusicRGBA = {200,200,200,255}
|
||||
local pauseMenuShowLevelID = false
|
||||
local pauseMenuShowLevelID = true
|
||||
|
||||
local curMap = -1
|
||||
local audioMainPaused = false
|
||||
local audioMain = nil --Used for the main audio
|
||||
local audioSpecial = nil --Used for things like cap music
|
||||
local audioCurSeq = nil
|
||||
local audioMain --Used for the main audio
|
||||
local audioSpecial --Used for things like cap music
|
||||
local audioCurSeq
|
||||
|
||||
local bgms = {
|
||||
[55] = {audio='snow.ogg', loopEnd = 500, loopStart = 0, volume = -5, name="Frosty Citadel - Sonic Gaiden" }, -- Spire
|
||||
[56] = {audio='rainbow.ogg', loopEnd = 148.657, loopStart = 12.406, volume = -5, name="Rainbow Road - Coop Deluxe" }, -- Rainbow
|
||||
[57] = {audio='city.ogg', loopEnd = 500, loopStart = 06.975, volume = -5, name="City Outskirts - Sonic Megamix" } -- City
|
||||
[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 = 1, name="Rainbow Road - Coop Deluxe" },
|
||||
[57] = {audio='city.ogg', loopEnd = 500, loopStart = 06.975, volume = 1, name="City Outskirts - Sonic Megamix" }
|
||||
}
|
||||
|
||||
-- disable cap music
|
||||
function music()
|
||||
local np = gNetworkPlayers[0]
|
||||
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
|
||||
if bgms[np.currLevelNum] then
|
||||
stop_cap_music()
|
||||
end
|
||||
end
|
||||
|
||||
hook_event(HOOK_UPDATE, music)
|
||||
|
||||
function handleMusic()
|
||||
------------------------------------------------------
|
||||
------------------------------------------------------
|
||||
-- Handle stopping/starting of music --
|
||||
------------------------------------------------------
|
||||
--Handle main course music
|
||||
if (curMap ~= gNetworkPlayers[0].currLevelNum and gMarioStates[0].area.macroObjects ~= nil) then
|
||||
curMap = gNetworkPlayers[0].currLevelNum
|
||||
audioCurSeq = get_current_background_music()
|
||||
if (audioMain ~= nil) then
|
||||
------------------------------------------------------
|
||||
--Handle main course music
|
||||
if curMap ~= np.currLevelNum and m.area.macroObjects then
|
||||
curMap = np.currLevelNum
|
||||
audioCurSeq = get_current_background_music()
|
||||
if audioMain then
|
||||
audio_stream_stop(audioMain)
|
||||
audio_stream_destroy(audioMain)
|
||||
audioMain = nil
|
||||
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)
|
||||
audioMain = audio_stream_load(bgms[curMap].audio)
|
||||
if (audioMain ~= nil) then
|
||||
if audioMain then
|
||||
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)
|
||||
else
|
||||
djui_popup_create('Missing audio!: ' .. bgms[curMap].audio, 10)
|
||||
|
@ -50,77 +52,78 @@ function handleMusic()
|
|||
print("No audio for this map, so not stopping default: " .. curMap)
|
||||
end
|
||||
end
|
||||
--Handle cap music
|
||||
if (gMarioStates[0].capTimer > 0 and bgms[-2] ~= nil) then
|
||||
--Handle pausing main streamed music, if applicable.
|
||||
if (audioMain ~= nil and audioMainPaused == false) then
|
||||
audioMainPaused = true
|
||||
audio_stream_pause(audioMain)
|
||||
end
|
||||
--Start up cap music if it's defined.
|
||||
if (audioSpecial == nil) then
|
||||
--Handle cap music
|
||||
if m.capTimer > 0 and bgms[-2] then
|
||||
--Handle pausing main streamed music, if applicable.
|
||||
if audioMain and not audioMainPaused then
|
||||
audioMainPaused = true
|
||||
audio_stream_pause(audioMain)
|
||||
end
|
||||
--Start up cap music if it's defined.
|
||||
if not audioSpecial then
|
||||
set_background_music(0,0,0)
|
||||
stop_cap_music()
|
||||
audioSpecial = audio_stream_load(bgms[-2].audio)
|
||||
if (audioSpecial ~= nil) then
|
||||
audio_stream_set_looping(audioSpecial, true)
|
||||
audio_stream_play(audioSpecial, true, bgms[-2].volume)
|
||||
print("Playing cap audio " .. bgms[-2].name)
|
||||
else
|
||||
djui_popup_create('Missing audio!: ' .. bgms[-2].audio, 3)
|
||||
stop_cap_music()
|
||||
audioSpecial = audio_stream_load(bgms[-2].audio)
|
||||
if audioSpecial then
|
||||
audio_stream_set_looping(audioSpecial, true)
|
||||
audio_stream_play(audioSpecial, true, bgms[-2].volume)
|
||||
print("Playing cap audio " .. bgms[-2].name)
|
||||
else
|
||||
djui_popup_create('Missing audio!: ' .. bgms[-2].audio, 3)
|
||||
print("Attempted to load filed audio file, but couldn't find it on the system: " .. bgms[-2].audio)
|
||||
end
|
||||
end
|
||||
else
|
||||
if (audioSpecial ~= nil) then
|
||||
audio_stream_stop(audioSpecial)
|
||||
audio_stream_destroy(audioSpecial)
|
||||
audioSpecial = nil
|
||||
if (audioMain ~= nil and audioMainPaused == true) then
|
||||
audioMainPaused = false
|
||||
audio_stream_play(audioMain, false, bgms[curMap].volume)
|
||||
else
|
||||
set_background_music(0, audioCurSeq, 10)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (audioMain ~= nil) then
|
||||
local curPosition = audio_stream_get_position(audioMain)
|
||||
if (curPosition >= bgms[curMap].loopEnd ) then
|
||||
local minus = bgms[curMap].loopStart - bgms[curMap].loopEnd
|
||||
audio_stream_set_position(audioMain, curPosition - math.abs(minus))
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if audioSpecial then
|
||||
audio_stream_stop(audioSpecial)
|
||||
audio_stream_destroy(audioSpecial)
|
||||
audioSpecial = nil
|
||||
if audioMain and audioMainPaused then
|
||||
audioMainPaused = false
|
||||
audio_stream_play(audioMain, false, bgms[curMap].volume)
|
||||
else
|
||||
set_background_music(0, audioCurSeq, 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
if curPosition >= bgms[curMap].loopEnd then
|
||||
local minus = bgms[curMap].loopStart - bgms[curMap].loopEnd
|
||||
audio_stream_set_position(audioMain, curPosition - math.abs(minus))
|
||||
end
|
||||
end
|
||||
if audioSpecial then
|
||||
local curPosition = audio_stream_get_position(audioSpecial)
|
||||
if curPosition >= bgms[-2].loopEnd then
|
||||
local minus = bgms[-2].loopStart - bgms[-2].loopEnd
|
||||
audio_stream_set_position(audioSpecial, curPosition - math.abs(minus))
|
||||
end
|
||||
end
|
||||
if (audioSpecial ~= nil) then
|
||||
local curPosition = audio_stream_get_position(audioSpecial)
|
||||
if (curPosition >= bgms[-2].loopEnd) then
|
||||
local minus = bgms[-2].loopStart - bgms[-2].loopEnd
|
||||
audio_stream_set_position(audioSpecial, curPosition - math.abs(minus))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function hud_render()
|
||||
if (pauseMenuShouldShowMusic == true and is_game_paused()) then
|
||||
djui_hud_set_resolution(RESOLUTION_DJUI);
|
||||
djui_hud_set_font(FONT_NORMAL);
|
||||
if pauseMenuShouldShowMusic and is_game_paused() then
|
||||
djui_hud_set_resolution(RESOLUTION_DJUI)
|
||||
djui_hud_set_font(FONT_NORMAL)
|
||||
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 y = screenHeight - height
|
||||
djui_hud_set_color(pauseMenuMusicRGBA[1], pauseMenuMusicRGBA[2], pauseMenuMusicRGBA[3], pauseMenuMusicRGBA[4]);
|
||||
local text = "";
|
||||
if (pauseMenuShowLevelID == true) then
|
||||
text = "Level ID: " .. gNetworkPlayers[0].currLevelNum
|
||||
elseif (audioSpecial ~= nil) then
|
||||
text = "Music: " .. bgms[-2].name
|
||||
elseif (audioMain ~= nil) then
|
||||
text = "Music: " .. bgms[curMap].name
|
||||
end
|
||||
djui_hud_print_text(text, 5, y, 1);
|
||||
djui_hud_set_color(200,200,200,255)
|
||||
local text
|
||||
if pauseMenuShowLevelID then
|
||||
text = "Level ID: " .. np.currLevelNum
|
||||
elseif audioSpecial then
|
||||
text = "Music: " .. bgms[-2].name
|
||||
elseif audioMain then
|
||||
text = "Music: " .. bgms[curMap].name
|
||||
end
|
||||
djui_hud_print_text(text, 5, y, 1)
|
||||
end
|
||||
end
|
||||
hook_event(HOOK_ON_HUD_RENDER, hud_render)
|
||||
hook_event(HOOK_UPDATE, handleMusic)
|
||||
hook_event(HOOK_UPDATE, handleMusic)
|
||||
|
|
Loading…
Reference in a new issue