-
Notifications
You must be signed in to change notification settings - Fork 28
/
animatedtimer.lua
97 lines (84 loc) · 2.11 KB
/
animatedtimer.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
animatedtimer = class:new()
animatedtimerlist = {}
function animatedtimer:init(x, y, tileno)
self.x = x
self.y = y
self.quadi = 1
self.timer = 0
self.quadobj = tilequads[tileno]
self.tileno = tileno
self.delays = self.quadobj.delays
self.frametimes = {}
self.length = 0
for i = 1, #self.delays do
if not self.delays[i] then
notice.new("Animated Tile " .. tileno-90000 .. " doesn't\nhave delay for frame " .. i .. "!", notice.red, 4)
break
end
self.length = self.length + self.delays[i]
self.frametimes[i] = self.length
end
self.dir = 0
table.insert(animatedtimerlist, self)
end
function animatedtimer:update(dt)
local oldi = self:geti()
self.timer = self.timer + dt*self.dir
if self.timer > self.length then
self.timer = self.length
self.dir = 0
elseif self.timer < 0 then
self.timer = 0
self.dir = 0
end
local newi = self:geti()
if oldi ~= newi then
local oldcol = self.quadobj.properties[oldi].collision
local oldportalable = self.quadobj.properties[oldi].portalable
local props = self.quadobj.properties[newi]
if props and oldcol ~= props.collision then
if props.collision then
objects["tile"][tilemap(self.x, self.y)] = tile:new(self.x-1, self.y-1)
else
objects["tile"][tilemap(self.x, self.y)] = nil
checkportalremove(self.x, self.y)
end
end
if props and oldportalable ~= props.portalable then
if not props.portalable then
checkportalremove(self.x, self.y)
end
end
local b = objects["tile"][tilemap(self.x, self.y)]
if b then
b.PLATFORM = props.platform
b.PLATFORMDOWN = props.platformdown
b.PLATFORMLEFT = props.platformleft
b.PLATFORMRIGHT = props.platformright
end
end
end
function animatedtimer:input(t)
if t == "on" then
self.dir = 1
elseif t == "off" then
self.dir = -1
elseif t == "toggle" then
self.dir = -self.dir
if self.dir == 0 then
if self.timer == 0 then
self.dir = 1
else
self.dir = -1
end
end
end
end
function animatedtimer:geti()
for i = 2, #self.frametimes do
if self.timer > self.frametimes[i-1] and self.timer <= self.frametimes[i] then
return i
end
end
return 1
end