From e08e6895868450e06774f29eb825b525be7cc2f9 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 2 Apr 2021 19:33:56 +0200 Subject: [PATCH] feat: add transition system --- sonic-radiance.love/core/init.lua | 1 + sonic-radiance.love/core/modules/scenes.lua | 2 +- .../core/modules/transitions/default.lua | 14 ++++++ .../core/modules/transitions/init.lua | 3 ++ .../core/modules/transitions/parent.lua | 43 +++++++++++++++++++ sonic-radiance.love/core/scenemanager.lua | 1 + sonic-radiance.love/core/screen.lua | 33 ++++++++++++++ .../scenes/overworld/charsetmanager.lua | 4 +- 8 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 sonic-radiance.love/core/modules/transitions/default.lua create mode 100644 sonic-radiance.love/core/modules/transitions/init.lua create mode 100644 sonic-radiance.love/core/modules/transitions/parent.lua diff --git a/sonic-radiance.love/core/init.lua b/sonic-radiance.love/core/init.lua index 5a8da4c..964d970 100644 --- a/sonic-radiance.love/core/init.lua +++ b/sonic-radiance.love/core/init.lua @@ -97,6 +97,7 @@ function CoreSystem:update(dt) end self.scenemanager:update(dt) + self.screen:update(dt) end -- DRAW FUNCTIONS diff --git a/sonic-radiance.love/core/modules/scenes.lua b/sonic-radiance.love/core/modules/scenes.lua index d418541..7559768 100644 --- a/sonic-radiance.love/core/modules/scenes.lua +++ b/sonic-radiance.love/core/modules/scenes.lua @@ -72,7 +72,7 @@ function Scene:updateEnd(dt) end function Scene:updateWorld(dt) - if (self.world ~= nil) and (self.world.isActive) then + if ((self.world ~= nil) and (self.world.isActive) and core.screen:isActive()) then self.world:update(dt) end end diff --git a/sonic-radiance.love/core/modules/transitions/default.lua b/sonic-radiance.love/core/modules/transitions/default.lua new file mode 100644 index 0000000..cf056b0 --- /dev/null +++ b/sonic-radiance.love/core/modules/transitions/default.lua @@ -0,0 +1,14 @@ +local TransitionParent = require "core.modules.transitions.parent" +local DefaultTransition = TransitionParent:extend() + +function DefaultTransition:new(func, ox, oy, fadeOut) + DefaultTransition.super.new(self, func, ox, oy, fadeOut, "inQuad", "outQuad", 0.35, 0.15) +end + +function DefaultTransition:draw() + love.graphics.setColor(0,0,0,self.value) + love.graphics.rectangle("fill", 0, 0, 424, 240) + utils.graphics.resetColor() +end + +return DefaultTransition \ No newline at end of file diff --git a/sonic-radiance.love/core/modules/transitions/init.lua b/sonic-radiance.love/core/modules/transitions/init.lua new file mode 100644 index 0000000..7a2554b --- /dev/null +++ b/sonic-radiance.love/core/modules/transitions/init.lua @@ -0,0 +1,3 @@ +return { + default = require "core.modules.transitions.default" +} \ No newline at end of file diff --git a/sonic-radiance.love/core/modules/transitions/parent.lua b/sonic-radiance.love/core/modules/transitions/parent.lua new file mode 100644 index 0000000..0115d1c --- /dev/null +++ b/sonic-radiance.love/core/modules/transitions/parent.lua @@ -0,0 +1,43 @@ +local TransitionParent = Object:extend() +local TweenManager = require "game.modules.tweenmanager" + +function TransitionParent:new(func, ox, oy, fadeOut, easeIn, easeOut, duration, wait) + print(func, ox, oy, fadeOut, easeIn, easeOut, duration) + self.tween = TweenManager(self) + self:loadResources() + self.func = func + self.ox = ox or 0 + self.oy = oy or 0 + self.fadeOut = fadeOut + if (self.fadeOut) then + self.value = 1 + self.tween:newTween(wait, duration, {value = 0}, easeOut) + else + self.value = 0 + self.tween:newTween(0, duration, {value = 1}, easeIn) + end + self.tween:newTimer(duration + wait, "isOver") +end + +function TransitionParent:loadResources() + --vide par defaut +end + +function TransitionParent:update(dt) + self.tween:update(dt) +end + +function TransitionParent:timerResponse(timer) + if (timer == "isOver") then + if (self.func ~= nil) then + self.func() + end + core.screen:transitionOver(self.fadeOut) + end +end + +function TransitionParent:draw() + +end + +return TransitionParent \ No newline at end of file diff --git a/sonic-radiance.love/core/scenemanager.lua b/sonic-radiance.love/core/scenemanager.lua index d2b44eb..a760f26 100644 --- a/sonic-radiance.love/core/scenemanager.lua +++ b/sonic-radiance.love/core/scenemanager.lua @@ -130,6 +130,7 @@ function SceneManager:draw() self.currentScene:draw() self.currentScene.menusystem:draw() self.currentScene:drawEnd() + self.controller.screen:drawTransition() end self.controller.screen:cease() end diff --git a/sonic-radiance.love/core/screen.lua b/sonic-radiance.love/core/screen.lua index 8033749..aa6c666 100644 --- a/sonic-radiance.love/core/screen.lua +++ b/sonic-radiance.love/core/screen.lua @@ -39,6 +39,27 @@ function ScreenManager:new(controller) CScreen.setColor(0, 0, 0, 1) love.graphics.setDefaultFilter( "nearest", "nearest", 1 ) + + self.transition = nil + self.transitionOut = nil + self.isOpaque = false +end + +function ScreenManager:startTransition(transitionIn, transitionOut, func, x, y) + self.transition = transitionIn(func, x, y, false) + self.transitionOut = transitionOut(nil, x, y, true) +end + +function ScreenManager:transitionOver(fadeOut) + if (not fadeOut) then + self.transition = self.transitionOut + else + self.transition = nil + end +end + +function ScreenManager:isActive() + return ((self.transition == nil) and (not self.isOpaque)) end function ScreenManager:applySettings() @@ -55,6 +76,12 @@ function ScreenManager:applySettings() CScreen.update(width, height) end +function ScreenManager:update(dt) + if (self.transition ~= nil) then + self.transition:update(dt) + end +end + -- POINTER FUNCTIONS -- Translate the pointer according to the screen coordinates @@ -104,4 +131,10 @@ function ScreenManager:cease() CScreen.cease() end +function ScreenManager:drawTransition() + if (self.transition ~= nil) then + self.transition:draw() + end +end + return ScreenManager diff --git a/sonic-radiance.love/scenes/overworld/charsetmanager.lua b/sonic-radiance.love/scenes/overworld/charsetmanager.lua index df1c82f..71d975e 100644 --- a/sonic-radiance.love/scenes/overworld/charsetmanager.lua +++ b/sonic-radiance.love/scenes/overworld/charsetmanager.lua @@ -21,7 +21,9 @@ function Charset:new(scene) end function Charset:update(dt) - self.currentFrame = ((self.currentFrame + (dt*5)) % 4) + if (core.screen:isActive()) then + self.currentFrame = ((self.currentFrame + (dt*5)) % 4) + end end function Charset:addChar(ii, jj)