summaryrefslogtreecommitdiffhomepage
path: root/not/Timer.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-21 21:05:37 +0200
committerAki <nthirtyone@gmail.com>2017-09-21 21:05:37 +0200
commite9a450d65d4fb564691cdf651ef5771dd88303ae (patch)
treef49d29582dd6877f3b3c807c3f7d9d92d368f798 /not/Timer.lua
parenteb8302723cd85adca0fbaf505cfb315f1db0299a (diff)
parentb97985def64b8bd8f93a7b391b12333595432e52 (diff)
downloadroflnauts-e9a450d65d4fb564691cdf651ef5771dd88303ae.zip
roflnauts-e9a450d65d4fb564691cdf651ef5771dd88303ae.tar.gz
roflnauts-e9a450d65d4fb564691cdf651ef5771dd88303ae.tar.bz2
Merge branch 'maps'
Diffstat (limited to 'not/Timer.lua')
-rw-r--r--not/Timer.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/not/Timer.lua b/not/Timer.lua
new file mode 100644
index 0000000..9ae0de8
--- /dev/null
+++ b/not/Timer.lua
@@ -0,0 +1,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