48 lines
966 B
Lua
48 lines
966 B
Lua
local module = {}
|
|
|
|
function module.ticker(counts)
|
|
local ticker = {
|
|
counts = counts,
|
|
current = 0,
|
|
}
|
|
|
|
function ticker:update(dt)
|
|
self.current = self.current + 1
|
|
if self.current == self.counts then
|
|
self.current = 0
|
|
return true
|
|
else return false end
|
|
end
|
|
|
|
function ticker:reset()
|
|
self.current = 0
|
|
end
|
|
|
|
return ticker
|
|
end
|
|
|
|
function module.timer(seconds)
|
|
local timer = {
|
|
total = seconds,
|
|
lastUpdate = 0,
|
|
currentTime = 0,
|
|
}
|
|
|
|
function timer:update(dt)
|
|
self.currentTime = self.currentTime + dt
|
|
if self.currentTime - self.lastUpdate >= self.total then
|
|
self.lastUpdate = self.currentTime
|
|
self.currentTime = 0
|
|
return true
|
|
else return false end
|
|
end
|
|
|
|
function timer:reset()
|
|
self.lastUpdate = 0
|
|
self.currentTime = 0
|
|
end
|
|
|
|
return timer
|
|
end
|
|
|
|
return module |