Skip to content

Commit b2961e2

Browse files
Initial upload, original release #11
1 parent be2b434 commit b2961e2

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed

wallindicator.lua

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
wallindicator = class("wallindicator")
2+
3+
function wallindicator:init(x, y, r)
4+
self.x = x
5+
self.y = y
6+
self.r = {unpack(r)}
7+
table.remove(self.r, 1)
8+
table.remove(self.r, 1)
9+
10+
self.lighted = false
11+
12+
--default off
13+
if #self.r > 0 and self.r[1] ~= "link" then
14+
self.lighted = (self.r[1] == "true")
15+
table.remove(self.r, 1)
16+
end
17+
18+
self.input1state = "off"
19+
end
20+
21+
function wallindicator:link()
22+
while #self.r > 3 do
23+
for j, w in pairs(outputs) do
24+
for i, v in pairs(objects[w]) do
25+
if tonumber(self.r[3]) == v.cox and tonumber(self.r[4]) == v.coy then
26+
v:addoutput(self, self.r[2])
27+
end
28+
end
29+
end
30+
table.remove(self.r, 1)
31+
table.remove(self.r, 1)
32+
table.remove(self.r, 1)
33+
table.remove(self.r, 1)
34+
end
35+
end
36+
37+
function wallindicator:update()
38+
39+
end
40+
41+
function wallindicator:draw()
42+
love.graphics.setColor(255, 255, 255)
43+
local quad = 1
44+
if self.lighted then
45+
quad = 2
46+
end
47+
48+
love.graphics.drawq(wallindicatorimg, wallindicatorquad[quad], math.floor((self.x-1-xscroll)*16*scale), ((self.y-yscroll-1)*16-8)*scale, 0, scale, scale)
49+
end
50+
51+
function wallindicator:input(t, input)
52+
if input == "power" then
53+
if t == "on" and self.input1state == "off" then
54+
self.lighted = not self.lighted
55+
elseif t == "off" and self.input1state == "on" then
56+
self.lighted = not self.lighted
57+
elseif t == "toggle" then
58+
self.lighted = not self.lighted
59+
end
60+
61+
self.input1state = t
62+
end
63+
end

walltimer.lua

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
walltimer = class("walltimer")
2+
3+
function walltimer:init(x, y, r)
4+
self.x = x
5+
self.y = y
6+
self.cox = x
7+
self.coy = y
8+
9+
self.outtable = {}
10+
self.lighted = false
11+
self.time = 1
12+
self.quad = 1
13+
14+
self.input1state = "off"
15+
16+
--Input list
17+
self.r = {unpack(r)}
18+
table.remove(self.r, 1)
19+
table.remove(self.r, 1)
20+
--TIME
21+
if #self.r > 0 and self.r[1] ~= "link" then
22+
self.time = tonumber(self.r[1])
23+
table.remove(self.r, 1)
24+
end
25+
26+
self.timer = self.time
27+
end
28+
29+
function walltimer:link()
30+
while #self.r > 3 do
31+
for j, w in pairs(outputs) do
32+
for i, v in pairs(objects[w]) do
33+
if tonumber(self.r[3]) == v.cox and tonumber(self.r[4]) == v.coy then
34+
v:addoutput(self, self.r[2])
35+
end
36+
end
37+
end
38+
table.remove(self.r, 1)
39+
table.remove(self.r, 1)
40+
table.remove(self.r, 1)
41+
table.remove(self.r, 1)
42+
end
43+
end
44+
45+
function walltimer:addoutput(a, t)
46+
table.insert(self.outtable, {a, t})
47+
end
48+
49+
function walltimer:update(dt)
50+
if self.lighted then
51+
self.quad = 2
52+
elseif self.timer == self.time then
53+
self.quad = 1
54+
else
55+
self.timer = self.timer + dt
56+
local div = self.time/10
57+
for i = 1, 9 do
58+
if i == math.floor(self.timer*(1/div)) then
59+
self.quad = i+1
60+
end
61+
end
62+
63+
if self.timer >= self.time then
64+
self:out("off")
65+
self.timer = self.time
66+
end
67+
end
68+
end
69+
70+
function walltimer:draw()
71+
love.graphics.setColor(255, 255, 255)
72+
73+
love.graphics.drawq(walltimerimg, walltimerquad[self.quad], math.floor((self.x-1-xscroll)*16*scale), ((self.y-yscroll-1)*16-8)*scale, 0, scale, scale)
74+
end
75+
76+
function walltimer:out(t)
77+
for i = 1, #self.outtable do
78+
if self.outtable[i][1].input then
79+
self.outtable[i][1]:input(t, self.outtable[i][2])
80+
end
81+
end
82+
end
83+
84+
function walltimer:input(t, input)
85+
if input == "power" then
86+
if t == "on" and self.input1state == "off" then
87+
self:out("on")
88+
self.timer = self.time
89+
self.lighted = true
90+
self.quad = 2
91+
elseif t == "off" and self.input1state == "on" then
92+
self.lighted = false
93+
self.timer = 0
94+
elseif t == "toggle" then
95+
self.timer = 0
96+
self.quad = 2
97+
self.lighted = false
98+
self:out("on")
99+
end
100+
101+
self.input1state = t
102+
end
103+
end

0 commit comments

Comments
 (0)