forked from Mari0-CE/Mari0-Community-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
groundlight.lua
72 lines (62 loc) · 1.68 KB
/
groundlight.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
groundlight = class("groundlight")
function groundlight:init(x, y, dir, r)
self.x = x
self.y = y
self.dir = dir
self.timer = 0
self.input1state = "off"
self.lighted = false
--Input list
self.r = {unpack(r)}
table.remove(self.r, 1)
table.remove(self.r, 1)
--POWER
if #self.r > 0 and self.r[1] ~= "link" then
self.lighted = (self.r[1] == "true")
table.remove(self.r, 1)
end
end
function groundlight:link()
while #self.r > 3 do
for j, w in pairs(outputs) do
for i, v in pairs(objects[w]) do
if tonumber(self.r[3]) == v.cox and tonumber(self.r[4]) == v.coy then
v:addoutput(self, self.r[2])
end
end
end
table.remove(self.r, 1)
table.remove(self.r, 1)
table.remove(self.r, 1)
table.remove(self.r, 1)
end
end
function groundlight:update(dt)
if self.timer > 0 then
self.timer = self.timer - dt
if self.timer <= 0 then
self.timer = 0
self:input("off")
end
end
end
function groundlight:draw()
if self.lighted then
love.graphics.setColor(255 / 255, 122 / 255, 66 / 255, 255 / 255)
else
love.graphics.setColor(60 / 255, 188 / 255, 252 / 255, 255 / 255)
end
love.graphics.draw(entityquads[42+self.dir].image, entityquads[42+self.dir].quad, math.floor((self.x-1-xscroll)*16*scale), ((self.y-yscroll-1)*16-8)*scale, 0, scale, scale)
end
function groundlight:input(t, input)
if input == "power" then
if t == "on" and self.input1state == "off" then
self.lighted = not self.lighted
elseif t == "off" and self.input1state == "on" then
self.lighted = not self.lighted
elseif t == "toggle" then
self.lighted = not self.lighted
end
self.input1state = t
end
end