-
Notifications
You must be signed in to change notification settings - Fork 17
/
portalent.lua
102 lines (84 loc) · 2.14 KB
/
portalent.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
portalent = class("portalent")
function portalent:init(x, y, i, r)
self.cox = x
self.coy = y
self.x = x
self.y = y
self.dir = "up"
self.portal = i
self.id = 1
self.power = false
--Input list
self.input1state = "off"
self.r = {unpack(r)}
table.remove(self.r, 1)
table.remove(self.r, 1)
--DIRECTION
if #self.r > 0 and self.r[1] ~= "link" then
self.dir = self.r[1]
table.remove(self.r, 1)
end
--ID
if #self.r > 0 then
self.id = tonumber(self.r[1])
table.remove(self.r, 1)
end
--POWER
if #self.r > 0 and self.r[1] ~= "link" then
self.power = self.r[1] == "true"
table.remove(self.r, 1)
end
if not portals[self.id] then
portals[self.id] = portal:new(self.id)
end
if self.power then
self:trigger()
end
end
function portalent: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 portalent:update(dt)
end
function portalent:draw()
end
function portalent:input(t, input)
if input == "power" then
local oldpower = self.power
if t == "on" and self.input1state == "off" then
self.power = not self.power
elseif t == "off" and self.input1state == "on" then
self.power = not self.power
elseif t == "toggle" then
self.power = not self.power
end
if self.power and not oldpower then
self:trigger()
elseif not self.power and oldpower then
self:rem()
end
self.input1state = t
end
end
function portalent:trigger()
portals[self.id]:createportal(self.portal, self.x, self.y, self.dir, -1)
end
function portalent:rem()
if portals[self.id]["x" .. self.portal] == self.x and portals[self.id]["y" .. self.portal] == self.y and portals[self.id]["facing" .. self.portal] == self.dir then
portals[self.id]:removeportal(self.portal)
else
print("Portal wasn't removed because it isn't at this position")
end
end