function hud.init()

 if not DEDSERV then

  local hipmove = 0.2
  local hipbounce = 0.1

  local upleglength = 1

  local hipturn = 0.6
  local hipmiddle = -1

  local lowleglength = 1

  local kneeturn = 0.5
  local kneemiddle = 2

  local bodylength = 1.2
  local bodymove = 0.01
  local bodymiddle = -2

  local color_leg_front = color(190,170,160)
  local color_leg_back = color(160,140,130)
  local color_body = color(190,170,160)

  local function renderweapon(bitmap, name, x, y, scaling)
   local perspective = 3
   local weaponmodel = weapon_models[name]
   if not weaponmodel then
    weaponmodel = weapon_models["CUBE"]
   end
   local size = weaponmodel[1]
   local r = 2
   while weaponmodel[r] do
    local x1 = weaponmodel[r    ] * size
    local y1 = weaponmodel[r + 1] * size
    local z1 = weaponmodel[r + 2] * size + perspective
    local x2 = weaponmodel[r + 3] * size
    local y2 = weaponmodel[r + 4] * size
    local z2 = weaponmodel[r + 5] * size + perspective
    local colour = weaponmodel[r + 6]
    r = r + 7
    local xb1 = x1/z1 * scaling + x
    local yb1 = y1/z1 * scaling + y
    local xb2 = x2/z2 * scaling + x
    local yb2 = y2/z2 * scaling + y
    bitmap:linewu(xb1, yb1, xb2, yb2, colour)
   end
  end


  local function rendernumber(bitmap, number, x, y, color, size, skew)
   local x_t_l = size*(skew - 1) + x
   local x_t_r = size*(skew + 1) + x
   local x_m_l = -size*1 + x
   local x_m_r = size*1 + x
   local x_b_l = -size*(skew + 1) + x
   local x_b_r = size*(1 - skew) + x

   local y_t = -size*2 + y
   local y_m = y
   local y_b = size*2 + y

   if number == 0 then
    bitmap:linewu(x_t_l, y_t, x_t_r, y_t, color)
    bitmap:linewu(x_t_r, y_t, x_b_r, y_b, color)
    bitmap:linewu(x_b_r, y_b, x_b_l, y_b, color)
    bitmap:linewu(x_b_l, y_b, x_t_l, y_t,  color)
   elseif number == 1 then
    bitmap:linewu(x_t_r, y_t, x_b_r, y_b, color)
   elseif number == 2 then
    bitmap:linewu(x_t_l, y_t, x_t_r, y_t, color)
    bitmap:linewu(x_m_l, y_m, x_m_r, y_m, color)
    bitmap:linewu(x_b_r, y_b, x_b_l, y_b, color)
    bitmap:linewu(x_t_r, y_t, x_m_r, y_m, color)
    bitmap:linewu(x_m_l, y_m, x_b_l, y_b, color)
   elseif number == 3 then
    bitmap:linewu(x_t_r, y_t, x_b_r, y_b, color)
    bitmap:linewu(x_t_l, y_t, x_t_r, y_t, color)
    bitmap:linewu(x_m_l, y_m, x_m_r, y_m, color)
    bitmap:linewu(x_b_r, y_b, x_b_l, y_b, color)
   elseif number == 4 then
    bitmap:linewu(x_t_r, y_t, x_b_r, y_b, color)
    bitmap:linewu(x_m_l, y_m, x_m_r, y_m, color)
    bitmap:linewu(x_t_l, y_t, x_m_l, y_m, color)
   elseif number == 5 then
    bitmap:linewu(x_t_l, y_t, x_t_r, y_t, color)
    bitmap:linewu(x_m_l, y_m, x_m_r, y_m, color)
    bitmap:linewu(x_b_r, y_b, x_b_l, y_b, color)
    bitmap:linewu(x_t_l, y_t, x_m_l, y_m, color)
    bitmap:linewu(x_m_r, y_m, x_b_r, y_b, color)
   elseif number == 6 then
    bitmap:linewu(x_t_l, y_t, x_t_r, y_t, color)
    bitmap:linewu(x_m_l, y_m, x_m_r, y_m, color)
    bitmap:linewu(x_b_r, y_b, x_b_l, y_b, color)

    bitmap:linewu(x_m_r, y_m, x_b_r, y_b, color)
    bitmap:linewu(x_t_l, y_t, x_b_l, y_b, color)
   elseif number == 7 then
    bitmap:linewu(x_t_l, y_t, x_t_r, y_t, color)
    bitmap:linewu(x_t_r, y_t, x_b_r, y_b, color)
   elseif number == 8 then
    bitmap:linewu(x_t_l, y_t, x_t_r, y_t, color)
    bitmap:linewu(x_t_r, y_t, x_b_r, y_b, color)
    bitmap:linewu(x_b_r, y_b, x_b_l, y_b, color)
    bitmap:linewu(x_b_l, y_b, x_t_l, y_t, color)
    bitmap:linewu(x_m_l, y_m, x_m_r, y_m, color)
   elseif number == 9 then
    bitmap:linewu(x_t_l, y_t, x_t_r, y_t, color)
    bitmap:linewu(x_m_l, y_m, x_m_r, y_m, color)
    bitmap:linewu(x_b_r, y_b, x_b_l, y_b, color)
    bitmap:linewu(x_t_r, y_t, x_b_r, y_b, color)
    bitmap:linewu(x_t_l, y_t, x_m_l, y_m, color)
   end
  end

  local hudFont = fonts.liero

  function bindings.wormRender(x, y, worm, viewport, ownerPlayer)
   x = x + 0.5
   local player = worm:player()
   local ownViewport = ( ownerPlayer == player )

   local bitmap = viewport:bitmap()
   local angle = worm:angle()

   --RENDERING ARMOUR
   local frame = worm:data().frame

   if frame then
    frame_b = frame * 0.06283
    local size = 3.5
    local flipped
    if angle > 180 then
     flipped = -1
    else
     flipped = 1
    end

    --BACK LEG

    xhip = -hipmove*math.sin(frame_b) - 0.5
    yhip = math.sin(frame_b*2)*hipbounce

    local anglehip = hipturn * math.sin(frame_b)+hipmiddle
    xknee = xhip + math.cos(anglehip) * upleglength
    yknee = yhip - math.sin(anglehip) * upleglength

    local angleknee = kneeturn * math.cos(frame_b)+kneemiddle
    xfoot = xknee + math.cos(angleknee) * lowleglength
    yfoot = yknee + math.sin(angleknee) * lowleglength


    bitmap:linewu(x+size*flipped*xhip, y+size*yhip, x+size*flipped*xknee, y+size*yknee, color_leg_front)
    bitmap:linewu(x+size*flipped*xhip, y+size*yhip, x+size*flipped*xknee, y+size*yknee, color_leg_front)
    bitmap:linewu(x+size*flipped*xknee+flipped, y+size*yknee, x+size*flipped*xfoot+flipped, y+size*yfoot, color_leg_front)
    bitmap:linewu(x+size*flipped*xhip+flipped, y+size*yhip, x+size*flipped*xknee+flipped, y+size*yknee, color_leg_front)
  
    --FRONT LEG

    xhip = math.sin(frame_b) * hipmove - 0.5

    local anglehip = -math.sin(frame_b) * hipturn + hipmiddle
    xknee = xhip + math.cos(anglehip) * upleglength
    yknee = yhip - math.sin(anglehip) * upleglength

    local angleknee = -math.cos(frame_b) * kneeturn + kneemiddle
    xfoot = xknee + math.cos(angleknee) * lowleglength
    yfoot = yknee + math.sin(angleknee) * lowleglength


    bitmap:linewu(x+size*flipped*xhip, y+size*yhip, x+size*flipped*xknee, y+size*yknee, color_leg_front)
    bitmap:linewu(x+size*flipped*xknee, y+size*yknee, x+size*flipped*xfoot, y+size*yfoot, color_leg_front)

    bitmap:linewu(x+size*flipped*xhip+flipped, y+size*yhip, x+size*flipped*xknee+flipped, y+size*yknee, color_leg_front)
    bitmap:linewu(x+size*flipped*xknee+flipped, y+size*yknee, x+size*flipped*xfoot+flipped, y+size*yfoot, color_leg_front)
  
    --BODY/HEAD


    local anglebody
    if angle < 180 then
     anglebody = angle * bodymove + bodymiddle
    else
     anglebody = (360 - angle) * bodymove + bodymiddle
    end
    local xbody = xhip + math.cos(anglebody) * bodylength
    local ybody = yhip + math.sin(anglebody) * bodylength

    bitmap:linewu(x+size*flipped*xhip, y+size*yhip, x+size*flipped*xbody, y+size*ybody, color_body)
    bitmap:linewu(x+size*flipped*xhip+flipped, y+size*yhip, x+size*flipped*xbody+flipped, y+size*ybody, color_body)
    bitmap:linewu(x+size*flipped*xhip+flipped*3, y+size*yhip, x+size*flipped*xbody+flipped, y+size*ybody, color_body)

    bitmap:putpixelwu(x+size*flipped*xbody+flipped, y+size*ybody+0.8, color(255,128,128))
   
   end  




   if ownViewport then

--WEAPON NAME (MODEL IN THIS CASE)
    if worm:is_changing() then
     local weapon_pos = player:data().weapon_pos
     if weapon_pos then
      local weapon_list = player:data().weapon_list
      local weapon_changing = player:data().weapon_changing
      local weapon_current = worm:current_weapon():type():name()
      for a =0, 5 do
       local name = weapon_list[(a + weapon_pos - 1) % 5 +1]:name() 
       local dx, dy = angle_vector(a*72 + weapon_changing, 25)
       local size = 30
       if name == weapon_current then
        size = 70
       end
       renderweapon(bitmap, name, x+dx, y+dy, size)
      end    
     end 
    end

--CROSSHAIR-LIKE THING	
    local dx, dy = angle_vector(angle, 25)
    local xpos, ypos = x + dx, y + dy
    for i = 0, 7 do
     local dx, dy = angle_vector(i * 40, 1.4)
     bitmap:putpixelwu(xpos+dx, ypos+dy, color(0,255,0))
    end

   else

--TARGETED/CURSOR
    local health = worm:health()
    local w = worm:current_weapon()
    local ammo
    if w:is_reloading() then
     ammo = 100 - w:reload_time() / w:type():reload_time() * 100
    else
     ammo = w:ammo() / w:type():ammo() * 100
    end

    local targeted = worm:data().HUD_targeted  
    if targeted then
     if targeted < 1 then
      gfx_set_add(128)
      for a=1, health, 7 do
       local dx, dy = angle_vector(a * 0.8 + 50, 10)
       bitmap:putpixelwu(x + dx, y + dy, color(255,0,0))
      end
      for a=1, ammo, 7 do
       local dx, dy = angle_vector(-a * 0.8 + 310, 10)
       bitmap:putpixelwu(x + dx, y + dy, color(0,0, 255))
      end
     end
     gfx_set_add(128)
     local radius = (targeted * 40 + 36)^0.5
     local rotation = worm:data().HUD_rotation
     if not rotation then
      rotation = 0
     end
     local cursor_color = color(64,255,64)
     for a=1, 360, 60 do
      dx, dy = angle_vector(a + rotation, 1)
      bitmap:linewu(x + dx * radius, y + dy * radius, x + dx * (radius + 3), y + dy * (radius + 3), cursor_color)
     end
    end
    gfx_reset_blending()			
   
    if not options.hideNames then
     fonts.minifont:render( bitmap, worm:player():name(), x, y - 10, color(255, 255, 255), Font.Formatting + Font.CenterH + Font.CenterV )
    end
   end
  end

--TARGETING???
  function bindings.playerUpdate(ownerplayer)
   if ownerplayer:is_local() then
    local ownerworm = ownerplayer:worm()
    local x1, y1 = ownerworm:pos()
    for player in game_players() do
     if not player:is_local() then
      local worm = player:worm()
      local x2, y2 = worm:pos()
      local angle = vector_direction(x1, y1, x2, y2) + 360
      local dangle = (angle - ownerworm:angle()) % 360
      if (dangle < 30 or dangle > 330) and not map_is_blocked(x1, y1, x2, y2) then
       local targeted = worm:data().HUD_targeted
       if targeted then
        targeted = targeted - 1
        if targeted < 0 then
         targeted = 0
         local rotation = worm:data().HUD_rotation
         if rotation then 
          rotation = (rotation + 3) % 360
         else
          rotation = 3
         end
         worm:data().HUD_rotation = rotation
        end
       else
        targeted = 30
       end
       worm:data().HUD_targeted = targeted
      else
       worm:data().HUD_targeted = nil
      end
     end
    end
   end
  end


--HEHE, FINALLY THE ACTUAL HUD AFTER ALL THOSE STUPID WORMS

  function bindings.viewportRender(viewport, worm)
   local player = worm:player()
   local bitmap = viewport:bitmap()
   local health = worm:health()

   if health > 0 then
    local width = bitmap:w()
    local height = bitmap:h()

    local middle = height/2
    local pivot_h = width-200
    gfx_set_add(128)
    for a=60, health * 0.6 + 60 do
     local x1, y1 = angle_vector(a,170)
     bitmap:linewu(pivot_h+x1,middle+y1,pivot_h+x1*1.1, middle+y1*1.1, color(255,0,0))
    end

    local w = worm:current_weapon()
    local ammo
    local ammocounter
    if w:is_reloading() then
     ammo = 100 - w:reload_time() / w:type():reload_time() * 100
     ammocounter = w:reload_time()
    else
     ammo = w:ammo() / w:type():ammo() * 100
     ammocounter = w:ammo()
    end
    for a=60, ammo * 0.6 + 60 do
     local x1, y1 = angle_vector(a,170)
     bitmap:linewu(200-x1,middle+y1,200-x1*1.1, middle+y1*1.1, color(0,0,255))
    end 

    
    local digit1 = math.floor(ammocounter * 0.01)
    local digit2 = math.floor((ammocounter % 100) * 0.1)
    local digit3 = math.floor(ammocounter % 10)
    rendernumber(bitmap, digit1, 15, 225, color(0,0,255), 4, -1)
    rendernumber(bitmap, digit2, 25, 225, color(0,0,255), 4, -1)
    rendernumber(bitmap, digit3, 35, 225, color(0,0,255), 4, -1)


    local digit1 = math.floor(health * 0.01)
    local digit2 = math.floor((health % 100) * 0.1)
    local digit3 = math.floor(health % 10)

    rendernumber(bitmap, digit1, width - 35, 225, color(255,0,0), 4, 1)
    rendernumber(bitmap, digit2, width - 25, 225, color(255,0,0), 4, 1)
    rendernumber(bitmap, digit3, width - 15, 225, color(255,0,0), 4, 1)

    local kills = player:kills()
    
    local digit1 = math.floor(kills * 0.01)
    local digit2 = math.floor((kills % 100) * 0.1)
    local digit3 = kills % 10

    rendernumber(bitmap, digit1, width - 35, 15, color(255,255,255), 4, -1)
    rendernumber(bitmap, digit2, width - 25, 15, color(255,255,255), 4, -1)
    rendernumber(bitmap, digit3, width - 15, 15, color(255,255,255), 4, -1)
    gfx_reset_blending()

   
   end    

   

   if health <= 0 then
    hudFont:render( bitmap, "You are dead... Press [JUMP] to respawn!", bitmap:w()/2, 12, color(255, 255, 255), Font.Shadow + Font.CenterH )
   end
			

  end

 end -- of not DEDSERV
end