1laserdetector = class:new() 2 3function laserdetector:init(x, y, dir) 4 self.cox = x 5 self.coy = y 6 self.dir = dir 7 8 self.drawable = false 9 10 self.outtable = {} 11 self.allowclear = true 12 self.out = "off" 13end 14 15function laserdetector:update(dt) 16 self.allowclear = true 17 18 if self.out ~= self.prevout then 19 self.prevout = self.out 20 for i = 1, #self.outtable do 21 if self.outtable[i].input then 22 self.outtable[i]:input(self.out) 23 end 24 end 25 end 26end 27 28function laserdetector:input(t) 29 self.allowclear = false 30 if t == "on" then 31 self.out = "on" 32 end 33end 34 35function laserdetector:draw() 36 local rot = 0 37 if self.dir == "down" then 38 rot = math.pi/2 39 elseif self.dir == "left" then 40 rot = math.pi 41 elseif self.dir == "up" then 42 rot = math.pi*1.5 43 end 44 love.graphics.draw(laserdetectorimg, math.floor((self.cox-xscroll-0.5)*16*scale), (self.coy-1)*16*scale, rot, scale, scale, 8, 8) 45end 46 47function laserdetector:addoutput(a) 48 table.insert(self.outtable, a) 49end 50 51function laserdetector:clear() 52 if self.allowclear then 53 self.allowclear = false 54 self.out = "off" 55 end 56end