src: add a basic scene system
This commit is contained in:
parent
e45cfca2bb
commit
586409bf5b
6 changed files with 164 additions and 0 deletions
|
@ -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()
|
||||
|
|
47
sonic-radiance.love/core/modules/scenes.lua
Normal file
47
sonic-radiance.love/core/modules/scenes.lua
Normal file
|
@ -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
|
51
sonic-radiance.love/core/scenemanager.lua
Normal file
51
sonic-radiance.love/core/scenemanager.lua
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
3
sonic-radiance.love/scenes/init.lua
Normal file
3
sonic-radiance.love/scenes/init.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
return {
|
||||
test = require "scenes.test_scene"
|
||||
}
|
47
sonic-radiance.love/scenes/test_scene/init.lua
Normal file
47
sonic-radiance.love/scenes/test_scene/init.lua
Normal file
|
@ -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
|
Loading…
Reference in a new issue