Mothback/data/scripts/lights.lua

65 lines
1.2 KiB
Lua
Raw Normal View History

2021-10-25 23:19:22 +00:00
Lights = {}
LightTimer = 0
function CreateDarkness()
2021-10-25 23:23:57 +00:00
return love.graphics.newCanvas(game.width, game.height)
2021-10-25 23:19:22 +00:00
end
function CreateLight(x,y,range)
local o = {}
o.pos = {
x = x,
y = y
}
o.range = range
o.flicker = 0
table.insert(Lights,o)
return o
end
function DoDarkness()
love.graphics.setColor(0,0,0)
love.graphics.rectangle("fill",0,0,game.width,game.height)
end
function DoLights()
LightTimer = LightTimer + 1
if LightTimer >= 3 then
LightTimer = LightTimer - 3
for _, light in pairs(Lights) do
light.flicker = math.random(-1,1)
end
end
love.graphics.setBlendMode("replace")
-- first, border
love.graphics.setColor(1,1,1)
for _, light in pairs(Lights) do
love.graphics.circle(
"fill",
light.pos.x - Camera.pos.x,
light.pos.y - Camera.pos.y,
light.range + light.flicker + 1
)
end
love.graphics.setColor(0,0,0,0)
-- then, light
for _, light in pairs(Lights) do
love.graphics.circle(
"fill",
light.pos.x - Camera.pos.x,
light.pos.y - Camera.pos.y,
light.range + light.flicker
)
end
love.graphics.setBlendMode("alpha")
end
function DoBorder()
end
function DrawDarkness()
2021-10-25 23:23:57 +00:00
love.graphics.draw(Canvas.Darkness, 0, 0, 0, 0.5, 0.5)
2021-10-25 23:19:22 +00:00
end