zombiesurvival-evolved/gamemodes/zombiesurvival/entities/effects/damagenumber.lua

88 lines
2 KiB
Lua
Raw Permalink Normal View History

2014-10-02 08:49:54 +08:00
EFFECT.LifeTime = 3
local TEXT_ALIGN_CENTER = TEXT_ALIGN_CENTER
local TEXT_ALIGN_BOTTOM = TEXT_ALIGN_BOTTOM
2014-10-02 08:49:54 +08:00
local draw = draw
local cam = cam
local Particles = {}
local col = Color(220, 0, 0)
local colprop = Color(220, 220, 0)
hook.Add("PostDrawTranslucentRenderables", "DrawDamage", function()
if #Particles == 0 then return end
local done = true
local curtime = CurTime()
local ang = EyeAngles()
ang:RotateAroundAxis(ang:Up(), -90)
ang:RotateAroundAxis(ang:Forward(), 90)
if GAMEMODE.DamageNumberThroughWalls then
cam.IgnoreZ(true)
end
2014-10-02 08:49:54 +08:00
for _, particle in pairs(Particles) do
if particle and curtime < particle.DieTime then
local c = particle.Type == 1 and colprop or col
done = false
c.a = math.Clamp(particle.DieTime - curtime, 0, 1) * 220
cam.Start3D2D(particle:GetPos(), ang, 0.1 * GAMEMODE.DamageNumberScale)
draw.SimpleText(particle.Amount, "ZS3D2DFont2", 0, 0, c, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
2014-10-02 08:49:54 +08:00
cam.End3D2D()
end
end
if GAMEMODE.DamageNumberThroughWalls then
cam.IgnoreZ(false)
end
2014-10-02 08:49:54 +08:00
if done then
Particles = {}
end
end)
local gravity = Vector(0, 0, -500)
function EFFECT:Init(data)
local pos = data:GetOrigin()
local amount = data:GetMagnitude()
local Type = data:GetScale()
local velscal = GAMEMODE.DamageNumberSpeed
2014-10-02 08:49:54 +08:00
local vel = VectorRand()
vel.z = math.Rand(0.7, 0.98)
vel:Normalize()
local emitter = ParticleEmitter(pos)
local particle = emitter:Add("sprites/glow04_noz", pos)
particle:SetDieTime(2)
particle:SetStartAlpha(0)
particle:SetEndAlpha(0)
particle:SetStartSize(0)
particle:SetEndSize(0)
particle:SetCollide(true)
particle:SetBounce(0.7)
particle:SetAirResistance(32)
particle:SetGravity(gravity * (velscal ^ 2))
particle:SetVelocity(math.Clamp(amount, 5, 50) * 4 * vel * velscal)
2014-10-02 08:49:54 +08:00
particle.Amount = amount
particle.DieTime = CurTime() + 2 * GAMEMODE.DamageNumberLifetime
2014-10-02 08:49:54 +08:00
particle.Type = Type
table.insert(Particles, particle)
emitter:Finish() emitter = nil collectgarbage("step", 64)
2014-10-02 08:49:54 +08:00
end
function EFFECT:Think()
return false
end
function EFFECT:Render()
end