aboutsummaryrefslogtreecommitdiff
path: root/gamemode/client/healthbar.lua
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/client/healthbar.lua')
-rw-r--r--gamemode/client/healthbar.lua107
1 files changed, 107 insertions, 0 deletions
diff --git a/gamemode/client/healthbar.lua b/gamemode/client/healthbar.lua
new file mode 100644
index 0000000..d9a050c
--- /dev/null
+++ b/gamemode/client/healthbar.lua
@@ -0,0 +1,107 @@
+
+hook.Add( "HUDShouldDraw", "HideHUD", function( name )
+ if name == "CHudHealth" then return false end
+end )
+
+--A function that rotates a point around another point
+local function rotatepoint(x,y,cx,cy,rot)
+ rot = math.rad(rot)
+ local cs,sn = math.cos(rot),math.sin(rot)
+ local px = x * cs - y * sn;
+ local py = x * sn + y * cs;
+ return px,py
+end
+
+--Add a function to the draw library to draw elipses for blood
+local segments = 20
+local fade = 0.5
+function draw.DrawElipse(x,y,radius,elong,rotation)
+ rotation = math.rad(rotation)
+ local cir = {}
+ table.insert( cir, { x = x, y = y, u = fade, v = fade } )
+ for i = 0, segments do
+ local a = math.rad( ( i / segments ) * -360 )
+ local xu,yu = math.sin(a),math.cos(a)
+ local xpos = xu * radius * elong
+ local ypos = yu * radius
+ local cs,sn = math.cos(rotation),math.sin(rotation)
+ xpos,ypos = xpos * cs - ypos * sn, xpos * sn + ypos * cs
+ table.insert( cir, {
+ x = x + xpos,
+ y = y + ypos,
+ u = 1,
+ v = 1 } )
+ end
+ surface.DrawPoly( cir )
+end
+
+local blobs = {}
+local lastpos = 0
+local delpoint = ScrH()
+hook.Add( "Tick", "Hudpaintbloodtick",function()
+ for k,v in pairs(blobs) do
+ if v.y > delpoint then
+ blobs[k] = nil
+ else
+ blobs[k] = {
+ ["x"] = v.x + v.xv,
+ ["y"] = v.y + v.yv,
+ ["xv"] = v.xv,
+ ["yv"] = v.yv + 1,
+ }
+ end
+ end
+end)
+
+local lasthealth
+local width,height = ScrW(),ScrH()
+local padding = height / 32
+local barheight = height / 16
+local obarlength = width / 4
+local barlength = obarlength
+local xs,ys = padding,height - padding - barheight
+hook.Add( "HUDPaint", "HUD_DrawHealth", function()
+
+ --Spawn a bunch of blobs if our health has changed
+ local health = LocalPlayer():Health()
+ if lasthealth == nil then
+ lasthealth = health
+ end
+ if health ~= lasthealth then
+ local difference = lasthealth - health
+ barlength = obarlength * (health/100)
+ for i=0,difference*3 do
+ local rtime = math.random()
+ timer.Simple(rtime,function()
+ local yvel = -20 + math.random(10)
+ local xvel = (math.random()*5)
+ local xpos = padding + xs + barlength - difference - 5
+ local ypos = ys + (math.random() * barheight)
+ table.insert(blobs,{
+ x = xpos,
+ y = ypos,
+ xv = xvel,
+ yv = yvel,
+ })
+ end)
+ end
+ lasthealth = health
+ end
+
+ --Draw the current health thing
+ surface.SetDrawColor(100,100,100,100)
+ surface.DrawRect( xs, ys, obarlength, barheight)
+ surface.SetDrawColor( 150, 0, 0, 255 )
+ surface.DrawRect( xs, ys, barlength, barheight )
+
+ --Draw the animation for blobs
+ for k,v in pairs(blobs) do
+ --Elongation is based on velocity
+ local elong = (v.yv^2 + v.xv^2)^0.5
+ elong = elong/5
+ elong = math.Clamp(elong,1,3)
+ --Rotation is also based on velcotiy
+ local rot = math.deg(math.atan(v.yv/v.xv))
+ draw.DrawElipse(v.x,v.y,10/elong,elong,rot)
+ end
+end )