-
Notifications
You must be signed in to change notification settings - Fork 17
/
regiontrigger.lua
87 lines (71 loc) · 2.07 KB
/
regiontrigger.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
regiontrigger = class("regiontrigger")
function regiontrigger:init(x, y, r)
self.x = x
self.y = y
self.cox = x
self.coy = y
self.checktable = "all"
self.outtable = {}
--Input list
self.r = {unpack(r)}
table.remove(self.r, 1)
table.remove(self.r, 1)
self.checktable = {}
for a,b in pairs(self.r) do
dbprint(a,b)
end
--TRIGGER ON PLAYER?
if #self.r > 0 and self.r[1] ~= "link" then
if self.r[1] == "true" then
table.insert(self.checktable, "player")
end
table.remove(self.r, 1)
end
--TRIGGER ON ENEMY?
if #self.r > 0 and self.r[1] ~= "link" then
if self.r[1] == "true" or self.r[1] == "all" then
table.insert(self.checktable, "enemy")
elseif tonumber(self.r[1]) then
table.insert(self.checktable, self.r[1])
end
table.remove(self.r, 1)
end
--REGION
if #self.r > 0 then
local s = self.r[1]:split(":")
self.regionX, self.regionY, self.regionwidth, self.regionheight = s[2], s[3], tonumber(s[4]), tonumber(s[5])
if string.sub(self.regionX, 1, 1) == "m" then
self.regionX = -tonumber(string.sub(self.regionX, 2))
end
if string.sub(self.regionY, 1, 1) == "m" then
self.regionY = -tonumber(string.sub(self.regionY, 2))
end
self.regionX = tonumber(self.regionX) + self.x - 1
self.regionY = tonumber(self.regionY) + self.y - 1
table.remove(self.r, 1)
end
self.out = "off"
end
function regiontrigger:update(dt)
local col = checkrect(self.regionX, self.regionY, self.regionwidth, self.regionheight, self.checktable)
if self.out == "off" and #col > 0 then
self.out = "on"
for i = 1, #self.outtable do
if self.outtable[i][1].input then
self.outtable[i][1]:input(self.out, self.outtable[i][2])
end
end
elseif self.out == "on" and #col == 0 then
self.out = "off"
for i = 1, #self.outtable do
if self.outtable[i][1].input then
self.outtable[i][1]:input(self.out, self.outtable[i][2])
end
end
end
end
function regiontrigger:draw()
end
function regiontrigger:addoutput(a, t)
table.insert(self.outtable, {a, t})
end