forked from Stabyourself/mari0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pushbutton.lua
54 lines (44 loc) · 1.04 KB
/
pushbutton.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
pushbutton = class:new()
function pushbutton:init(x, y, dir)
self.cox = x
self.coy = y
self.dir = dir
self.out = false
self.outtable = {}
adduserect(x-10/16, y-12/16, 4/16, 12/16, self)
self.timer = pushbuttontime
end
function pushbutton:update(dt)
if self.timer < pushbuttontime then
self.timer = self.timer + dt
if self.timer >= pushbuttontime then
self.pusheddown = false
self.timer = pushbuttontime
end
end
end
function pushbutton:draw()
local quad = 1
if self.pusheddown then
quad = 2
end
local horscale = scale
if self.dir == "right" then
horscale = -scale
end
love.graphics.draw(pushbuttonimg, pushbuttonquad[quad], math.floor((self.cox-0.5-xscroll)*16*scale), (self.coy-1.5)*16*scale, 0, horscale, scale, 8)
end
function pushbutton:addoutput(a)
table.insert(self.outtable, a)
end
function pushbutton:used()
if self.timer == pushbuttontime then
self.pusheddown = true
self.timer = 0
for i = 1, #self.outtable do
if self.outtable[i].input then
self.outtable[i]:input("toggle")
end
end
end
end