check in
This commit is contained in:
commit
2ac8f77cb4
3 changed files with 172 additions and 0 deletions
25
lua/defs.lua
Normal file
25
lua/defs.lua
Normal file
|
@ -0,0 +1,25 @@
|
|||
-- Define gametype (could be done with a .soc but uuuuuh maybe later??)
|
||||
G_AddGametype({
|
||||
name = "HideAndSeek",
|
||||
identifier = "hidenseek",
|
||||
typeoflevel = TOL_RACE,
|
||||
rules = GTR_NOPOSITION,
|
||||
intermissiontype = int_none,
|
||||
description = "Hide and run away from the seekers until you get caught, then join the hunt!"
|
||||
})
|
||||
|
||||
rawset(_G, "hns_hidingtime", CV_RegisterVar({
|
||||
name = "hns_hidingtime",
|
||||
defaultvalue = "15",
|
||||
flags = CV_NETVAR,
|
||||
possiblevalue = CV_Unsigned,
|
||||
}))
|
||||
|
||||
rawset(_G, "HNSDEFS", {
|
||||
GameState = {
|
||||
Loading = 0,
|
||||
LevelStart = 1,
|
||||
Hiding = 2,
|
||||
Seeking = 3,
|
||||
},
|
||||
})
|
83
lua/gamelogic.lua
Normal file
83
lua/gamelogic.lua
Normal file
|
@ -0,0 +1,83 @@
|
|||
local function countPlayers()
|
||||
local count = 0
|
||||
for p in players.iterate
|
||||
if p.spectator
|
||||
continue
|
||||
end
|
||||
count = $ + 1
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
|
||||
local function resetState()
|
||||
return {
|
||||
active = false,
|
||||
state = HNSDEFS.GameState.Loading,
|
||||
seekstart = 0,
|
||||
}
|
||||
end
|
||||
|
||||
rawset(_G, "HNS", resetState())
|
||||
|
||||
addHook("MapChange", function(mapnum)
|
||||
if not (gametype == GT_HIDENSEEK) return end
|
||||
|
||||
-- Reset vars
|
||||
HNS = resetState()
|
||||
end)
|
||||
|
||||
local loadTime = 10 * TICRATE
|
||||
|
||||
addHook("MapLoad", function(mapnum)
|
||||
if not (gametype == GT_HIDENSEEK) return end
|
||||
|
||||
-- Welcome to the setup zone, enjoy your brief stay
|
||||
|
||||
local player_count = countPlayers()
|
||||
HNS.active = true --player_count > 1
|
||||
HNS.seekstart = loadTime + TICRATE * hns_hidingtime.value
|
||||
|
||||
if not HNS.active
|
||||
-- I guess you get to look around??
|
||||
return
|
||||
end
|
||||
|
||||
local initial_seeker = P_RandomRange(1, player_count) -- Be like P_RandomRange: inclusive!
|
||||
|
||||
-- Init state for each player
|
||||
local index = 1
|
||||
for p in players.iterate
|
||||
p.hns = {
|
||||
seeker = index == initial_seeker
|
||||
}
|
||||
index = $ + 1
|
||||
|
||||
-- If hider, set invisible
|
||||
if not p.hns.seeker
|
||||
p.hyudorotimer = HNS.seekstart
|
||||
end
|
||||
end
|
||||
|
||||
HNS.state = HNSDEFS.GameState.LevelStart
|
||||
end)
|
||||
|
||||
addHook("ThinkFrame", function()
|
||||
if HNS.state == HNSDEFS.GameState.LevelStart
|
||||
if leveltime > loadTime
|
||||
HNS.state = HNSDEFS.GameState.Hiding
|
||||
HNS.seekstart = leveltime + (hns_hidingtime.value * TICRATE)
|
||||
end
|
||||
elseif HNS.state == HNSDEFS.GameState.Hiding
|
||||
if leveltime >= HNS.seekstart
|
||||
HNS.state = HNSDEFS.GameState.Seeking
|
||||
-- Play seek start sound!
|
||||
--TODO
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
addHook("NetVars", function(net)
|
||||
-- Sync your shit here
|
||||
HNS = net($)
|
||||
end)
|
64
lua/hud.lua
Normal file
64
lua/hud.lua
Normal file
|
@ -0,0 +1,64 @@
|
|||
-- 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)
|
Loading…
Reference in a new issue