Mothback/data/scripts/lights.lua

74 lines
1.6 KiB
Lua
Raw Normal View History

2021-10-25 23:19:22 +00:00
Lights = {}
LightTimer = 0
function CreateDarkness()
return love.graphics.newCanvas(game.width/game.scale, game.height/game.scale)
2021-10-25 23:19:22 +00:00
end
function CreateLight(x,y,range,lum,flicker)
2021-10-25 23:19:22 +00:00
local o = {}
o.pos = {
x = x,
y = y
}
o.range = range
o.lum = lum or 1
o.flicker_value = flicker or 2
2021-10-25 23:19:22 +00:00
o.flicker = 0
2021-10-27 09:06:08 +00:00
o.dim = 0
o.flicker_speed = flicker_speed or 60/12
o.flicker_time = 0
2021-10-25 23:19:22 +00:00
table.insert(Lights,o)
2022-01-18 19:24:49 +00:00
2021-10-25 23:19:22 +00:00
return o
end
2021-10-27 09:06:08 +00:00
function SetDarkness()
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle("fill",0,0,game.width ,game.height)
2021-10-27 09:06:08 +00:00
end
2021-10-25 23:19:22 +00:00
function DoLights()
2021-10-27 09:06:08 +00:00
for _, light in pairs(Lights) do
light.flicker_time = light.flicker_time + 1
if light.flicker_time >= light.flicker_speed then
light.flicker_time = light.flicker_time - light.flicker_speed
light.flicker = 0 + math.random(0,1)
light.flicker = math.min(math.max(light.flicker, -light.flicker_value),light.flicker_value)
2021-10-27 09:06:08 +00:00
end
2021-10-25 23:19:22 +00:00
end
love.graphics.setBlendMode("replace")
love.graphics.setColor(1,1,1,1)
for _, light in pairs(Lights) do
if light.range ~= 0 then
love.graphics.circle(
"fill",
(light.pos.x - Camera.pos.x) / game.scale,
(light.pos.y - Camera.pos.y) / game.scale,
(light.range + light.flicker + 1) / game.scale
)
end
2021-10-27 09:06:08 +00:00
end
love.graphics.setColor(0,0,0,0)
for _, light in pairs(Lights) do
if light.range ~= 0 then
love.graphics.circle(
"fill",
(light.pos.x - Camera.pos.x) / game.scale,
(light.pos.y - Camera.pos.y) / game.scale,
(light.range + light.flicker) / game.scale
)
end
2021-10-25 23:19:22 +00:00
end
love.graphics.setBlendMode("alpha")
end
function DoBorder()
end
function DrawDarkness()
love.graphics.draw(Canvas.Darkness, 0, 0, 0, 2/game.scale)
2021-10-27 09:06:08 +00:00
end