-
Notifications
You must be signed in to change notification settings - Fork 17
/
actionblock.lua
68 lines (59 loc) · 1.5 KB
/
actionblock.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
57
58
59
60
61
62
63
64
65
66
67
68
actionblock = class("actionblock")
function actionblock:init(x, y)
self.cox = x
self.coy = y
self.x = x-1
self.y = y-1
self.speedx = 0
self.speedy = 0
self.width = 1
self.height = 1
self.active = true
self.static = true
self.category = 2
self.mask = {true}
self.state = "off"
self.outtable = {}
self.timer = blockbouncetime
end
function actionblock:addoutput(a, t)
table.insert(self.outtable, {a, t})
end
function actionblock:update(dt)
if self.timer < blockbouncetime then
self.timer = math.min(blockbouncetime, self.timer + dt)
end
end
function actionblock:draw()
local bounceyoffset = 0
if self.timer < blockbouncetime then
if self.timer < blockbouncetime/2 then
bounceyoffset = self.timer / (blockbouncetime/2) * blockbounceheight
else
bounceyoffset = (2 - self.timer / (blockbouncetime/2)) * blockbounceheight
end
end
local q = 1
if self.state == "on" then
q = 2
end
love.graphics.draw(actionblockimg, wallindicatorquad[q], math.floor((self.x-xscroll)*16*scale), math.floor((self.y-.5-yscroll-bounceyoffset)*16*scale), 0, scale, scale)
end
function actionblock:floorcollide(a, b, c, d)
if self.state == "off" then
self.state = "on"
else
self.state = "off"
end
if self.timer == blockbouncetime then
self.timer = 0
end
self:out(self.state)
end
function actionblock:out(t)
for i = 1, #self.outtable do
if self.outtable[i][1].input then
self.outtable[i][1]:input(t, self.outtable[i][2])
end
end
end