summaryrefslogtreecommitdiffhomepage
path: root/not/Timer.lua
blob: 9ae0de88dad0de9d660d0ca72183e554a0d724d8 (plain)
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
Timer = require "not.Trigger":extends()

function Timer:new (delay)
	Timer.__super.new(self)
	self.delay = delay
	self.left = 0
	self.active = false
	self.restart = false
end

function Timer:start ()
	self.left = self.delay
	self.active = true
end

function Timer:update (dt)
	if self.active then
		if self.left < 0 then
			self:emit()
			self.active = false
			if self.restart then
				self:start()
			end
		else
			self.left = self.left - dt
		end
	end
end

return Timer