-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.lua
45 lines (38 loc) · 803 Bytes
/
timer.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
timer = {}
local timers = {}
local lastValue = {}
function timer.reset(name)
timers[name] = 0
lastValue[name] = 0
end
function timer.update(dt)
for name, time in pairs(timers) do
timers[name] = time + dt
end
end
function timer.check(name, time)
if timers[name] < time then
return false
end
timer.reset(name)
return true
end
function timer.peek(name)
return timers[name]
end
function timer.tick(name, secondSfx, tenSecondSfx, minuteSfx)
local value = math.floor(timers[name])
if value > lastValue[name] then
lastValue[name] = value
if value % 60 == 0 then
minuteSfx:play()
elseif value % 10 == 0 then
tenSecondSfx:play()
else
secondSfx:play()
end
end
end
function timer.add(name, time)
timers[name] = timers[name] + time
end