forked from Stabyourself/mari0
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
laserdetector.lua
56 lines (47 loc) · 1.04 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
laserdetector = class:new()
function laserdetector:init(x, y, dir)
self.cox = x
self.coy = y
self.dir = dir
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].input then
self.outtable[i]:input(self.out)
end
end
end
end
function laserdetector:input(t)
self.allowclear = false
if t == "on" then
self.out = "on"
end
end
function laserdetector:draw()
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, math.floor((self.cox-xscroll-0.5)*16*scale), (self.coy-1)*16*scale, rot, scale, scale, 8, 8)
end
function laserdetector:addoutput(a)
table.insert(self.outtable, a)
end
function laserdetector:clear()
if self.allowclear then
self.allowclear = false
self.out = "off"
end
end