summaryrefslogtreecommitdiffhomepage
path: root/not/SceneManager.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-08-13 02:26:55 +0200
committerAki <nthirtyone@gmail.com>2017-08-13 02:26:55 +0200
commitb1cf14d64a2d3e28683db87190c4b2c7799c259d (patch)
treee45dac5cc6ce5265e3e3e2c914eb7cc92a820b8b /not/SceneManager.lua
parent0dd01913fe0eefc7ba4bc0797877f40fdedf9315 (diff)
parented62b573417bdc85bec616f6016846b02de4c906 (diff)
downloadroflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.zip
roflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.tar.gz
roflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.tar.bz2
Merge branch 'multi'maps
Diffstat (limited to 'not/SceneManager.lua')
-rw-r--r--not/SceneManager.lua62
1 files changed, 62 insertions, 0 deletions
diff --git a/not/SceneManager.lua b/not/SceneManager.lua
new file mode 100644
index 0000000..c076448
--- /dev/null
+++ b/not/SceneManager.lua
@@ -0,0 +1,62 @@
+--- `SceneManager`
+-- Used for changing single active scene.
+-- TODO: Extend functionality for more than one active scene (eg. overlay menu).
+SceneManager = require "not.Object":extends()
+
+function SceneManager:new ()
+ self.scenes = {}
+end
+
+-- This function should be removed when multiple scenes will be handled properly by SceneManager and other things.
+function SceneManager:changeScene (scene)
+ table.remove(self.scenes, #self.scenes)
+ return self:addScene(scene)
+end
+
+function SceneManager:addScene (scene)
+ table.insert(self.scenes, scene)
+ return scene
+end
+
+-- Not nice, not nice.
+function SceneManager:removeTopScene ()
+ table.remove(self.scenes, #self.scenes)
+end
+
+function SceneManager:getAllScenes ()
+ return self.scenes
+end
+
+function SceneManager:update (dt)
+ for _,scene in pairs(self:getAllScenes()) do
+ if not scene:isSleeping() then
+ scene:update(dt)
+ end
+ end
+end
+
+function SceneManager:draw ()
+ for _,scene in pairs(self:getAllScenes()) do
+ if not scene:isHidden() then
+ scene:draw()
+ end
+ end
+end
+
+function SceneManager:controlpressed (set, action, key)
+ for _,scene in pairs(self:getAllScenes()) do
+ if not scene:isInputDisabled() then
+ scene:controlpressed(set, action, key)
+ end
+ end
+end
+
+function SceneManager:controlreleased (set, action, key)
+ for _,scene in pairs(self:getAllScenes()) do
+ if not scene:isInputDisabled() then
+ scene:controlreleased(set, action, key)
+ end
+ end
+end
+
+return SceneManager