-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.lua
More file actions
47 lines (36 loc) · 921 Bytes
/
Copy pathtimer.lua
File metadata and controls
47 lines (36 loc) · 921 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
42
43
44
45
46
47
-- ##################################################################
-- # Package: timer.
-- # This package contains code for creating timers.
-- ##################################################################
local timer = {}
local Timer = {running = true}
function Timer:new(period)
local o = {period = period, currentTime = period}
setmetatable(o, self)
self.__index = self
print(o.currentTime)
return o
end
function Timer:reset()
self.running = false
self.currentTime = 0
end
function Timer:restart()
self.running = true
self.currentTime = self.period
end
function Timer:update(dt)
if not self.running then
return false
end
self.currentTime = self.currentTime - dt
if self.currentTime <= 0 then
self:reset()
return true
end
return false
end
function timer.newTimer(period)
return Timer:new(period)
end
return timer