
include('shared.lua')

local matLight 		= Material( "sprites/light_ignorez" )

function ENT:Initialize()

	self.PixVis = util.GetPixelVisibleHandle()
	
end

/*---------------------------------------------------------
   Name: Draw
---------------------------------------------------------*/
function ENT:Draw()

	self.BaseClass.Draw( self )
	
	local LightNrm = self.Entity:GetAngles():Up()
	local ViewDot = EyeVector():Dot( LightNrm )
	if ( ViewDot < 0 ) then return end
	
	local LightPos = self.Entity:GetPos() + LightNrm * -9
	local Visibile	= util.PixelVisible( LightPos, 16, self.PixVis )
	
	// glow sprite
	render.SetMaterial( matLight )
	
	local Size = math.Clamp( 512 * (1 - Visibile*ViewDot),128, 512 )
	local r, g, b, a = self.Entity:GetColor()
	local Col = Color( r, g, b, 200*Visibile*ViewDot )
	
	render.DrawSprite( LightPos, Size, Size, Col, Visibile * ViewDot )
	
end

/*---------------------------------------------------------
   Overridden because I want to show the name of the 
   player that spawned it..
---------------------------------------------------------*/
function ENT:GetOverlayText()

	if ( SinglePlayer() ) then
		return ""
	end

	return self:GetPlayerName()	
	
end
