summaryrefslogtreecommitdiff
path: root/data/artery
diff options
context:
space:
mode:
authorApickx <apickx@cogarr.com>2018-03-24 20:40:54 -0400
committerApickx <apickx@cogarr.com>2018-03-24 20:40:54 -0400
commit2568d8b47bfb77ba3a748e189901846b4ae7860c (patch)
tree524b2beacf754927df82aecf6dcd8887e0521ba0 /data/artery
downloadartery_stamina-2568d8b47bfb77ba3a748e189901846b4ae7860c.tar.gz
artery_stamina-2568d8b47bfb77ba3a748e189901846b4ae7860c.tar.bz2
artery_stamina-2568d8b47bfb77ba3a748e189901846b4ae7860c.zip
Inital commit
Inital commit
Diffstat (limited to 'data/artery')
-rw-r--r--data/artery/global/cl_stamina.lua78
-rw-r--r--data/artery/global/sh_stamina.lua21
-rw-r--r--data/artery/global/sv_stamina.lua34
3 files changed, 133 insertions, 0 deletions
diff --git a/data/artery/global/cl_stamina.lua b/data/artery/global/cl_stamina.lua
new file mode 100644
index 0000000..96e6e2b
--- /dev/null
+++ b/data/artery/global/cl_stamina.lua
@@ -0,0 +1,78 @@
+AddCSLuaFile()
+if SERVER then return end
+local stamina = nrequire("sh_stamina.lua")
+
+local width, height = ScrW(), ScrH()
+local padding = height / 32
+local barheight = height / 16
+local xs, ys = padding, height - (padding * 2) - (barheight * 2)
+local obarlength = width / 4
+local strikechance = 0.2
+local barlength = obarlength
+local strikerate = 0.4
+local strikes = {}
+local strike_segments = 10
+local erat_mult = 1.5
+
+--Holds the player's stamina
+local mystamina = stamina.default_stamina
+net.Receive("art_sync_stamina",function()
+ mystamina = net.ReadTable()
+end)
+
+timer.Create("Energybar_lightening_timer", strikerate, 0, function()
+ if math.random() < strikechance then
+ local strike = {
+ fade = 0,
+ points = {}
+ }
+ local segment_height = barheight / strike_segments
+ local last = math.random(barheight * erat_mult,barlength - (barheight * erat_mult))
+ for i = 1,strike_segments + 1 do
+ local emtsh = erat_mult * segment_height
+ strike.points[#strike.points + 1] = {
+ x = last,
+ y = (i - 1) * segment_height
+ }
+ last = last + math.random(-emtsh,emtsh)
+ end
+ table.insert(strikes,strike)
+ end
+end)
+
+hook.Add("HUDPaint", "HUD_DrawEnergy", function()
+ --Background
+ surface.SetDrawColor(100, 100, 100, 100)
+ surface.DrawRect(xs, ys, obarlength, barheight)
+ --Foreground
+ barlength = (obarlength / 100) * stamina.getStamina(LocalPlayer())
+ surface.SetDrawColor(0, 0, 150, 255)
+ surface.DrawRect(xs, ys, barlength, barheight)
+ --Heighlighting/shadows
+ surface.SetTexture( surface.GetTextureID("gui/gradient.vtf") )
+ surface.SetDrawColor( 0, 0, 0, 255 )
+ surface.DrawTexturedRectRotated( xs + (barlength / 2), ys + (barheight / 4) * 3, barheight / 2, barlength,90)
+ surface.SetDrawColor( 255, 255, 255, 50 )
+ surface.DrawTexturedRectRotated( xs + (barlength / 2), ys + (barheight / 8), barheight / 4, barlength,270)
+ --Draw lightening strikes
+ for k,strike in pairs(strikes) do
+ --Strikes all use the same alpha
+ surface.SetDrawColor(255,255,255,255 - strike.fade)
+ strike.fade = strike.fade + 20
+ for i = 2,#strike.points do
+ local sp = strike.points
+ surface.DrawLine(sp[i-1].x + xs,sp[i-1].y + ys,sp[i].x + xs,sp[i].y + ys)
+ end
+ if strike.fade == 0 then
+ table.remove(strikes,k)
+ end
+ end
+end)
+
+function stamina.getStamina(who)
+ assert(who == LocalPlayer(),"Tried to get stamina of something other than localplayer!")
+ local ret = stamina.calc_stamina(mystamina)
+ return ret
+end
+
+return stamina
diff --git a/data/artery/global/sh_stamina.lua b/data/artery/global/sh_stamina.lua
new file mode 100644
index 0000000..ab905eb
--- /dev/null
+++ b/data/artery/global/sh_stamina.lua
@@ -0,0 +1,21 @@
+local stam = {}
+
+stam.default_stamina = {
+ regen = 5,
+ cooldown = 1,
+ stamina = 100,
+ max_stamina = 100,
+ last_stamina_use = CurTime()
+}
+
+function stam.calc_stamina(tbl)
+ local tregen = tbl.last_stamina_use + tbl.cooldown
+ local calc = tbl.stamina
+ if CurTime() > tregen then
+ --regened number
+ calc = calc + (tbl.regen * (CurTime() - tregen))
+ end
+ return math.Clamp(calc,0,tbl.max_stamina)
+end
+
+return stam
diff --git a/data/artery/global/sv_stamina.lua b/data/artery/global/sv_stamina.lua
new file mode 100644
index 0000000..8a32598
--- /dev/null
+++ b/data/artery/global/sv_stamina.lua
@@ -0,0 +1,34 @@
+util.AddNetworkString("art_sync_stamina")
+
+local stam = nrequire("sh_stamina.lua")
+
+--Table that holds stamina for all players
+local staminatbl = {}
+
+local function sync_stamina(who)
+ net.Start("art_sync_stamina")
+ net.WriteTable(staminatbl[who])
+ net.Send(who)
+end
+
+hook.Add( "PlayerInitialSpawn", "stamina_init",function(ply)
+ staminatbl[ply] = table.Copy(stam.default_stamina)
+end )
+hook.Add( "PlayerDisconnected", "stamina_desc",function(ply)
+ staminatbl[ply] = nil
+end )
+
+function stam.getStamina(who)
+ staminatbl[who] = staminatbl[who] or table.Copy(stam.default_stamina)
+ return stam.calc_stamina(staminatbl[who])
+end
+
+function stam.takeStamina(who,num)
+ staminatbl[who] = staminatbl[who] or table.Copy(stam.default_stamina)
+ local ttbl = staminatbl[who]
+ ttbl.stamina = stam.getStamina(who) - num
+ ttbl.last_stamina_use = CurTime()
+ sync_stamina(who)
+end
+
+return stam