forked from Rapidjonte/NESTRIS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.lua
More file actions
41 lines (33 loc) · 710 Bytes
/
timer.lua
File metadata and controls
41 lines (33 loc) · 710 Bytes
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
local Timer = Class:extend()
function Timer:new(duration, repeated, func)
self.duration = duration
self.repeated = repeated or false
self.func = func or nil
self.time = 0
self.active = false
self.finished = false
end
function Timer:activate()
self.active = true
self.time = 0
self.finished = false
end
function Timer:deactivate()
self.active = false
self.finished = true
end
function Timer:update(dt)
if self.active then
self.time = self.time + dt
if self.time >= self.duration then
if self.func and self.time ~= 0 then
self.func()
end
self:deactivate()
if self.repeated then
self:activate()
end
end
end
end
return Timer