diff --git a/sonic-radiance.love/core/init.lua b/sonic-radiance.love/core/init.lua index 8886ed4..5e7f764 100644 --- a/sonic-radiance.love/core/init.lua +++ b/sonic-radiance.love/core/init.lua @@ -31,17 +31,25 @@ local Options = require "core.options" local Input = require "core.input" local Screen = require "core.screen" local Lang = require "core.lang" +local SceneManager= require "core.scenemanager" function CoreSystem:new() self.debug = DebugSystem(self) self.options = Options(self) self.input = Input(self) self.screen = Screen(self) + self.scenemanager = SceneManager(self) end function CoreSystem:update(dt) self.debug:update(dt) self.input:update(dt) + + self.scenemanager:update(dt) +end + +function CoreSystem:draw() + self.scenemanager:draw() end function CoreSystem:exit() diff --git a/sonic-radiance.love/core/modules/scenes.lua b/sonic-radiance.love/core/modules/scenes.lua new file mode 100644 index 0000000..e964b94 --- /dev/null +++ b/sonic-radiance.love/core/modules/scenes.lua @@ -0,0 +1,47 @@ +-- scenes.lua :: the scene object, that aim to give a better control to the engine +-- to the different scene, without having to call too much boilerplate + +--[[ + Copyright © 2019 Kazhnuz + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +]] + +local Scene = Object:extend() + +function Scene:new() + +end + +function Scene:register() + core.scenemanager.currentScene = self +end + +function Scene:update(dt) + -- Empty function, is just here to avoid crash +end + +function Scene:draw() + +end + +function Scene:clear() + +end + +return Scene diff --git a/sonic-radiance.love/core/scenemanager.lua b/sonic-radiance.love/core/scenemanager.lua new file mode 100644 index 0000000..5fac773 --- /dev/null +++ b/sonic-radiance.love/core/scenemanager.lua @@ -0,0 +1,51 @@ +-- scene.lua :: a basic scene management system, that work by sending the different +-- core functions to the scene, normally without the scene itself having to manage +-- them. + +--[[ + Copyright © 2019 Kazhnuz + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +]] + +local SceneManager = Object:extend() + +function SceneManager:new(controller) + self.controller = controller + self.currentScene = nil +end + +function SceneManager:update(dt) + if (self.currentScene ~= nil) then + self.currentScene:update(dt) + end +end + +function SceneManager:clearScene() + self.currentScene = nil +end + +function SceneManager:draw() + self.controller.screen:apply() + if (self.currentScene ~= nil) then + self.currentScene:draw(dt) + end + self.controller.screen:cease() +end + +return SceneManager diff --git a/sonic-radiance.love/main.lua b/sonic-radiance.love/main.lua index f49a368..49b02af 100644 --- a/sonic-radiance.love/main.lua +++ b/sonic-radiance.love/main.lua @@ -26,12 +26,20 @@ Object = require "libs.classic" Core = require "core" Game = require "game" +scenes = require "scenes" + function love.load() core = Core() game = Game() + + scenes.test() end function love.update(dt) core:update(dt) game:update(dt) end + +function love.draw() + core:draw() +end diff --git a/sonic-radiance.love/scenes/init.lua b/sonic-radiance.love/scenes/init.lua new file mode 100644 index 0000000..49d7467 --- /dev/null +++ b/sonic-radiance.love/scenes/init.lua @@ -0,0 +1,3 @@ +return { + test = require "scenes.test_scene" +} diff --git a/sonic-radiance.love/scenes/test_scene/init.lua b/sonic-radiance.love/scenes/test_scene/init.lua new file mode 100644 index 0000000..1ef1b49 --- /dev/null +++ b/sonic-radiance.love/scenes/test_scene/init.lua @@ -0,0 +1,47 @@ +-- scenes/test :: a basic test scene + +--[[ + Copyright © 2019 Kazhnuz + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +]] + +local Scene = require "core.modules.scenes" +local TestScene = Scene:extend() + +function TestScene:new() + TestScene.super.new() + + self.i = 0 + + self:register() +end + +function TestScene:update(dt) + self.i = self.i + dt +end + +function TestScene:draw() + love.graphics.setColor(0, 0, 1, 1) + love.graphics.rectangle("fill", 0, 0, 424, 240) + + love.graphics.setColor(0, 0, 0, 1) + love.graphics.print(self.i, 16, 16) +end + +return TestScene