forked from Stabyourself/mari0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.lua
54 lines (43 loc) · 1.07 KB
/
button.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
button = class:new()
function button:init(x, y)
self.cox = x
self.coy = y
--PHYSICS STUFF
self.x = x-15/16
self.y = y-3/16
self.width = 30/16
self.height = 3/16
self.static = true
self.active = false
self.category = 22
self.mask = {true}
self.drawable = false
self.out = false
self.outtable = {}
end
function button:update(dt)
local colls = checkrect(self.x+5/16, self.y-2/16, 20/16, 1, {"player", "goomba", "koopa", "box"})
if (#colls > 0) ~= self.out then
self.out = not self.out
for i = 1, #self.outtable do
if self.outtable[i].input then
if self.out then
self.outtable[i]:input("on")
else
self.outtable[i]:input("off")
end
end
end
end
end
function button:draw()
local ymod = 0
if self.out then
ymod = 1
end
love.graphics.draw(buttonbuttonimg, math.floor((self.x+5/16-xscroll)*16*scale), (self.y*16-10+ymod)*scale, 0, scale, scale)
love.graphics.draw(buttonbaseimg, math.floor((self.x-1/16-xscroll)*16*scale), (self.y*16-8)*scale, 0, scale, scale)
end
function button:addoutput(a)
table.insert(self.outtable, a)
end