diff options
Diffstat (limited to 'data/artery/global/cl_stamina.lua')
| -rw-r--r-- | data/artery/global/cl_stamina.lua | 78 |
1 files changed, 78 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 |
