Mothback/code/lights.lua

48 lines
959 B
Lua
Raw Normal View History

Light = {}
LoadedObjects.Lights = {}
2021-10-25 23:19:22 +00:00
function Light:New(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
o.lum = lum or 1
o.color = color or {1,1,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_time = 60/12
o.flicker_timer = 0
table.insert(LoadedObjects.Lights,o)
o.id = #LoadedObjects.Lights
setmetatable(o, self)
self.__index = self
2021-10-25 23:19:22 +00:00
return o
end
function Light:Kill()
if self.id ~= nil then
for _, e in pairs(LoadedObjects.Lights) do
if e.id > self.id then
2022-01-20 13:06:40 +00:00
e.id = e.id - 1
end
end
table.remove(LoadedObjects.Lights,self.id)
2022-01-20 13:06:40 +00:00
end
self = nil
2021-10-27 09:06:08 +00:00
end
function Light:Flicker()
self.flicker_timer = self.flicker_timer + 1
2021-10-27 09:06:08 +00:00
if self.flicker_timer >= self.flicker_time then
self.flicker_timer = self.flicker_timer - self.flicker_time
self.flicker = math.random(0,1)
self.flicker = math.min(math.max(self.flicker, -self.flicker_value), self.flicker_value)
2021-10-27 09:06:08 +00:00
end
end