-
Notifications
You must be signed in to change notification settings - Fork 28
/
laserdetector.lua
72 lines (63 loc) · 1.52 KB
/
laserdetector.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
laserdetector = class:new()
function laserdetector:init(x, y, dir, r)
self.cox = x
self.coy = y
self.dir = dir
self.detectslasers = true
self.detectslightbridges = false
self.r = {unpack(r)}
table.remove(self.r, 1)
table.remove(self.r, 1)
if #self.r > 0 and self.r[1] ~= "link" then
local v = convertr(self.r[1], {"string", "bool", "bool"}, true)
self.dir = v[1]
self.detectslasers = v[2]
self.detectslightbridges = v[3]
table.remove(self.r, 1)
end
self.drawable = false
self.outtable = {}
self.allowclear = true
self.out = "off"
end
function laserdetector:update(dt)
self.allowclear = true
if self.out ~= self.prevout then
self.prevout = self.out
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 laserdetector:input(t)
self.allowclear = false
if t == "on" then
self.out = "on"
end
end
function laserdetector:draw()
local quadi = 1
if self.out == "on" then
quadi = 2
end
local rot = 0
if self.dir == "down" then
rot = math.pi/2
elseif self.dir == "left" then
rot = math.pi
elseif self.dir == "up" then
rot = math.pi*1.5
end
love.graphics.draw(laserdetectorimg, laserdetectorquad[quadi], math.floor((self.cox-xscroll-0.5)*16*scale), (self.coy-1-yscroll)*16*scale, rot, scale, scale, 8, 8)
end
function laserdetector:addoutput(a, t)
table.insert(self.outtable, {a, t})
end
function laserdetector:clear()
if self.allowclear then
self.allowclear = false
self.out = "off"
end
end