2021-10-25 23:19:22 +00:00
|
|
|
Lights = {}
|
|
|
|
LightTimer = 0
|
|
|
|
|
|
|
|
function CreateDarkness()
|
2022-01-17 23:14:54 +00:00
|
|
|
return love.graphics.newCanvas(game.width/game.scale, game.height/game.scale)
|
2021-10-25 23:19:22 +00:00
|
|
|
end
|
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
function CreateLight(x,y,range,flicker,color,lum)
|
2021-10-25 23:19:22 +00:00
|
|
|
local o = {}
|
|
|
|
o.pos = {
|
|
|
|
x = x,
|
|
|
|
y = y
|
|
|
|
}
|
|
|
|
o.range = range
|
2021-11-28 02:38:30 +00:00
|
|
|
o.lum = lum or 1
|
2022-01-29 07:49:45 +00:00
|
|
|
o.color = color or {1,1,1}
|
2022-01-17 23:14:54 +00:00
|
|
|
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
|
2022-01-17 23:14:54 +00:00
|
|
|
o.flicker_speed = flicker_speed or 60/12
|
2021-11-28 02:38:30 +00:00
|
|
|
o.flicker_time = 0
|
2022-01-29 07:49:45 +00:00
|
|
|
|
2021-10-25 23:19:22 +00:00
|
|
|
table.insert(Lights,o)
|
2022-01-20 13:06:40 +00:00
|
|
|
o.id = #Lights
|
2021-10-25 23:19:22 +00:00
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
2022-01-20 13:06:40 +00:00
|
|
|
function KillLight(light)
|
|
|
|
if light.id ~= nil then
|
|
|
|
for _, e in pairs(Lights) do
|
|
|
|
if e.id > light.id then
|
|
|
|
e.id = e.id - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.remove(Lights,light.id)
|
|
|
|
end
|
|
|
|
light = nil
|
|
|
|
end
|
|
|
|
|
2021-10-27 09:06:08 +00:00
|
|
|
function SetDarkness()
|
2022-02-05 11:32:47 +00:00
|
|
|
love.graphics.setCanvas(Canvas.Darkness)
|
|
|
|
|
2021-10-27 09:06:08 +00:00
|
|
|
love.graphics.setColor(0,0,0,1)
|
2022-01-17 23:14:54 +00:00
|
|
|
love.graphics.rectangle("fill",0,0,game.width ,game.height)
|
2022-02-05 11:32:47 +00:00
|
|
|
|
|
|
|
love.graphics.setCanvas()
|
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
|
|
|
|
2022-02-05 11:32:47 +00:00
|
|
|
love.graphics.setCanvas(Canvas.Darkness)
|
|
|
|
|
2021-11-28 02:38:30 +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
|
2022-01-17 23:14:54 +00:00
|
|
|
light.flicker = 0 + math.random(0,1)
|
2021-11-28 02:38:30 +00:00
|
|
|
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
|
2022-02-07 08:24:41 +00:00
|
|
|
|
2021-11-28 02:38:30 +00:00
|
|
|
love.graphics.setBlendMode("replace")
|
2022-01-17 23:14:54 +00:00
|
|
|
for _, light in pairs(Lights) do
|
|
|
|
if light.range ~= 0 then
|
2022-01-29 07:49:45 +00:00
|
|
|
love.graphics.setColor(light.color[1],light.color[2],light.color[3],1)
|
2022-02-07 08:24:41 +00:00
|
|
|
local position = {
|
|
|
|
x = (light.pos.x - Camera.pos.x) / game.scale,
|
|
|
|
y = (light.pos.y - Camera.pos.y) / game.scale
|
|
|
|
}
|
|
|
|
local range = (1 + light.range + light.flicker) / game.scale
|
2022-01-17 23:14:54 +00:00
|
|
|
love.graphics.circle(
|
|
|
|
"fill",
|
2022-02-07 08:24:41 +00:00
|
|
|
position.x,
|
|
|
|
position.y,
|
|
|
|
range
|
2022-01-17 23:14:54 +00:00
|
|
|
)
|
|
|
|
end
|
2021-10-27 09:06:08 +00:00
|
|
|
end
|
2022-02-07 08:24:41 +00:00
|
|
|
love.graphics.setColor(0,0,0,0)
|
2022-01-17 23:14:54 +00:00
|
|
|
for _, light in pairs(Lights) do
|
|
|
|
if light.range ~= 0 then
|
2022-02-05 11:32:47 +00:00
|
|
|
local position = {
|
|
|
|
x = (light.pos.x - Camera.pos.x) / game.scale,
|
|
|
|
y = (light.pos.y - Camera.pos.y) / game.scale
|
|
|
|
}
|
|
|
|
local range = (light.range + light.flicker) / game.scale
|
2021-11-28 02:38:30 +00:00
|
|
|
love.graphics.circle(
|
2022-02-07 08:24:41 +00:00
|
|
|
"fill",
|
|
|
|
position.x,
|
|
|
|
position.y,
|
|
|
|
range
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
love.graphics.setBlendMode("alpha")
|
|
|
|
love.graphics.setColor(0,0,0,1)
|
|
|
|
Shaders.InsideLight:send("game_scale", game.scale)
|
|
|
|
|
|
|
|
for _, light in pairs(Lights) do
|
|
|
|
if light.range ~= 0 then
|
|
|
|
local position = {
|
|
|
|
x = (light.pos.x - Camera.pos.x) / game.scale,
|
|
|
|
y = (light.pos.y - Camera.pos.y) / game.scale
|
|
|
|
}
|
|
|
|
local range = (light.range + light.flicker) / game.scale
|
|
|
|
Shaders.InsideLight:send("light_color", light.color)
|
|
|
|
Shaders.InsideLight:send("light_pos", {position.x*game.scale, position.y*game.scale})
|
|
|
|
Shaders.InsideLight:send("range", range)
|
|
|
|
love.graphics.setShader(Shaders.InsideLight)
|
2022-02-05 11:32:47 +00:00
|
|
|
love.graphics.circle(
|
|
|
|
"fill",
|
|
|
|
position.x,
|
|
|
|
position.y,
|
|
|
|
range
|
|
|
|
)
|
|
|
|
love.graphics.setShader()
|
2021-11-28 02:38:30 +00:00
|
|
|
end
|
2021-10-25 23:19:22 +00:00
|
|
|
end
|
2022-02-05 11:32:47 +00:00
|
|
|
|
|
|
|
love.graphics.setCanvas()
|
|
|
|
|
2021-10-25 23:19:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DoBorder()
|
2022-02-05 11:32:47 +00:00
|
|
|
love.graphics.setCanvas(Canvas.Darkness)
|
|
|
|
love.graphics.setCanvas()
|
2021-10-25 23:19:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DrawDarkness()
|
2022-02-07 08:24:41 +00:00
|
|
|
love.graphics.draw(Canvas.Darkness, 0, 0, 0, 1/game.scale)
|
2021-10-27 09:06:08 +00:00
|
|
|
end
|