1button = class:new() 2 3function button:init(x, y) 4 self.cox = x 5 self.coy = y 6 7 --PHYSICS STUFF 8 self.x = x-15/16 9 self.y = y-3/16 10 self.width = 30/16 11 self.height = 3/16 12 self.static = true 13 self.active = false 14 self.category = 22 15 16 self.mask = {true} 17 18 self.drawable = false 19 20 self.out = false 21 self.outtable = {} 22end 23 24function button:update(dt) 25 local colls = checkrect(self.x+5/16, self.y-2/16, 20/16, 1, {"player", "goomba", "koopa", "box"}) 26 27 if (#colls > 0) ~= self.out then 28 self.out = not self.out 29 for i = 1, #self.outtable do 30 if self.outtable[i].input then 31 if self.out then 32 self.outtable[i]:input("on") 33 else 34 self.outtable[i]:input("off") 35 end 36 end 37 end 38 end 39end 40 41function button:draw() 42 local ymod = 0 43 if self.out then 44 ymod = 1 45 end 46 47 love.graphics.draw(buttonbuttonimg, math.floor((self.x+5/16-xscroll)*16*scale), (self.y*16-10+ymod)*scale, 0, scale, scale) 48 49 love.graphics.draw(buttonbaseimg, math.floor((self.x-1/16-xscroll)*16*scale), (self.y*16-8)*scale, 0, scale, scale) 50end 51 52function button:addoutput(a) 53 table.insert(self.outtable, a) 54end