diff options
author | Aki <nthirtyone@gmail.com> | 2017-07-12 16:00:51 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-07-12 16:00:51 +0200 |
commit | 9af261cd204b999e6b2b5a44d5c5eb768f84c49d (patch) | |
tree | b5465cd344f01329c0d027b5345a23e15e1e2bc7 /not/SceneManager.lua | |
parent | 6c6e2fe6ec84ec57f6336fa9d6e4136c0e1c9513 (diff) | |
download | roflnauts-9af261cd204b999e6b2b5a44d5c5eb768f84c49d.zip roflnauts-9af261cd204b999e6b2b5a44d5c5eb768f84c49d.tar.gz roflnauts-9af261cd204b999e6b2b5a44d5c5eb768f84c49d.tar.bz2 |
Created Scene class
extended SceneManager a little bit to support multiple scenes
Diffstat (limited to 'not/SceneManager.lua')
-rw-r--r-- | not/SceneManager.lua | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/not/SceneManager.lua b/not/SceneManager.lua index 2e429c2..c9a8e20 100644 --- a/not/SceneManager.lua +++ b/not/SceneManager.lua @@ -3,31 +3,55 @@ -- 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) - if self.scene ~= nil then - self.scene:delete() - end - self.scene = scene + table.remove(self.scenes, #self.scenes) + return self:addScene(scene) +end + +function SceneManager:addScene (scene) + table.insert(self.scenes, scene) + return scene end -function SceneManager:getScene () - return self.scene +function SceneManager:getAllScenes () + return self.scenes end function SceneManager:update (dt) - self:getScene():update(dt) + for _,scene in pairs(self:getAllScenes()) do + if not scene:isSleeping() then + scene:update(dt) + end + end end function SceneManager:draw () - self:getScene():draw() + for _,scene in pairs(self:getAllScenes()) do + if not scene:isHidden() then + scene:draw() + end + end end function SceneManager:controlpressed (set, action, key) - self:getScene():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) - self:getScene():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 |