-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathnotgate.lua
67 lines (58 loc) · 1.17 KB
/
notgate.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
notgate = class:new()
function notgate:init(x, y, r)
self.x = x
self.y = y
self.cox = x
self.coy = y
self.r = r
self.outtable = {}
self.state = "on"
self.initial = true
end
function notgate:link()
if #self.r > 3 then
for j, w in pairs(outputs) do
for i, v in pairs(objects[w]) do
if tonumber(self.r[4]) == v.cox and tonumber(self.r[5]) == v.coy then
v:addoutput(self)
end
end
end
end
end
function notgate:addoutput(a)
table.insert(self.outtable, a)
end
function notgate:update(dt)
if self.initial then
self.initial = false
if self.state == "on" then
self:input("off")
end
end
end
function notgate:draw()
love.graphics.setColor(1, 1, 1)
love.graphics.draw(entitiesimg, entityquads[84].quad, math.floor((self.x-1-xscroll)*16*scale), ((self.y-1)*16-8)*scale, 0, scale, scale)
end
function notgate:out(t)
for i = 1, #self.outtable do
if self.outtable[i].input then
self.outtable[i]:input(t)
end
end
end
function notgate:input(t)
if t == "off" then
self.state = "on"
elseif t == "on" then
self.state = "off"
else
if self.state == "off" then
self.state = "on"
else
self.state = "off"
end
end
self:out(self.state)
end