HideAndSeek/lua/hud.lua
2024-06-02 00:02:10 +02:00

64 lines
2.2 KiB
Lua

-- Not splitscreen friendly
-- Why would it be?? Go play screencheat if you want peeking as a mechanic
local revealTime = 4 * TICRATE
local countdownTime = 7 * TICRATE
local function drawCountdown(v, num)
if num == 0 then num = "GO" end
local patch = v.cachePatch("K_CNT" .. num .. (leveltime%10>4 and "A" or "B"))
v.drawScaled(FRACUNIT*(160-patch.width/2), FRACUNIT*(100-patch.height/2), FRACUNIT, patch, V_SNAPTOTOP)
end
hud.add(function(v, p, c)
if not HNS.active return end
hud.disable("position")
hud.disable("time")
hud.disable("rankings")
-- This disables nametags but v2.3 has a misalignment bug
-- https://git.do.srb2.org/KartKrew/RingRacers/-/issues/145
hud.disable("check")
-- This disables minirankings but same as above
hud.disable("battlerankingsbumpers")
-- Ensure player has hns data (I don't even think this is the right way)
if not p.hns return end
if HNS.state == HNSDEFS.GameState.LevelStart
if leveltime > countdownTime
-- Show 3..2..1.. countdown
local remaining = (leveltime - countdownTime) / TICRATE
drawCountdown(v, max(0, 3 - remaining))
elseif leveltime > revealTime
if leveltime == revealTime
-- Play reveal sound!
end
-- Draw text
v.drawString(160, 80, "You are " .. (p.hns.seeker and "a seeker" or "a hider"), V_SNAPTOLEFT|V_SNAPTOTOP, "center")
end
elseif HNS.state == HNSDEFS.GameState.Hiding
-- Hack: show the Go! for another second after start
if leveltime < countdownTime+4*TICRATE
drawCountdown(v, 0)
end
v.drawString(160, 20, "HIDE SOMEWHERE!!", V_SNAPTOLEFT|V_SNAPTOTOP, "center")
local remaining = HNS.seekstart - leveltime
local minutes,seconds = G_TicsToMinutes(remaining, true), G_TicsToSeconds(remaining)
local mod, modAfter = "", ""
if remaining < TICRATE*10 then
mod = leveltime%4>2 and "\x82" or "\x85"
modAfter = string.format(".%01d", G_TicsToCentiseconds(remaining)/10)
end
v.drawString(160, 30, mod .. string.format("%02d:%02d", minutes, seconds) .. modAfter, V_SNAPTOLEFT|V_SNAPTOTOP, "center")
elseif HNS.state == HNSDEFS.GameState.Seeking
if leveltime < HNS.seekstart+2*TICRATE
local mod = leveltime%10>5 and "\x82" or "\x85"
v.drawString(160, 20, mod .. "THE SEEKERS HAVE BEEN UNLEASHED!", V_SNAPTOLEFT|V_SNAPTOTOP, "center")
end
end
end)