summaryrefslogtreecommitdiffhomepage
path: root/not
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-07-12 16:00:51 +0200
committerAki <nthirtyone@gmail.com>2017-07-12 16:00:51 +0200
commit9af261cd204b999e6b2b5a44d5c5eb768f84c49d (patch)
treeb5465cd344f01329c0d027b5345a23e15e1e2bc7 /not
parent6c6e2fe6ec84ec57f6336fa9d6e4136c0e1c9513 (diff)
downloadroflnauts-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')
-rw-r--r--not/Menu.lua2
-rw-r--r--not/Scene.lua32
-rw-r--r--not/SceneManager.lua44
-rw-r--r--not/World.lua4
4 files changed, 68 insertions, 14 deletions
diff --git a/not/Menu.lua b/not/Menu.lua
index 1688166..ea47993 100644
--- a/not/Menu.lua
+++ b/not/Menu.lua
@@ -1,7 +1,7 @@
--- `Menu`
-- It creates single screen of a menu
-- I do know that model I used here and in `World` loading configuration files is not flawless but I did not want to rewrite `World`s one but wanted to keep things similar at least in project scope.
-Menu = require "not.Object":extends()
+Menu = require "not.Scene":extends()
Menu.scale = getScale()
Menu.elements = --[[{not.Element}]]nil
diff --git a/not/Scene.lua b/not/Scene.lua
new file mode 100644
index 0000000..c770fe4
--- /dev/null
+++ b/not/Scene.lua
@@ -0,0 +1,32 @@
+--- `Scene`
+Scene = require "not.Object":extends()
+
+function Scene:new ()
+ self.sleeping = false
+ self.hidden = false
+ self.inputDisabled = false
+end
+
+-- Following setters and getters are a little bit too much, I think. But they do follow general coding directions.
+function Scene:setSleeping (sleeping)
+ self.sleeping = sleeping
+end
+function Scene:isSleeping ()
+ return self.sleeping
+end
+
+function Scene:setHidden (hidden)
+ self.hidden = hidden
+end
+function Scene:isHidden ()
+ return self.hidden
+end
+
+function Scene:setInputDisabled (inputDisabled)
+ self.inputDisabled = inputDisabled
+end
+function Scene:isInputDisabled ()
+ return self.inputDisabled
+end
+
+return Scene
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
diff --git a/not/World.lua b/not/World.lua
index 8108a8a..65ca59e 100644
--- a/not/World.lua
+++ b/not/World.lua
@@ -1,9 +1,7 @@
-require "not.Object"
-
--- `World`
-- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc.
-- TODO: Possibly move common parts of `World` and `Menu` to abstract class `Scene`.
-World = Object:extends()
+World = require "not.Scene":extends()
World.world =--[[love.physics.newWorld]]nil
World.Nauts =--[[{not.Hero}]]nil