feat: add transition system

This commit is contained in:
Kazhnuz 2021-04-02 19:33:56 +02:00
parent b1e308bf82
commit e08e689586
8 changed files with 99 additions and 2 deletions

View file

@ -97,6 +97,7 @@ function CoreSystem:update(dt)
end end
self.scenemanager:update(dt) self.scenemanager:update(dt)
self.screen:update(dt)
end end
-- DRAW FUNCTIONS -- DRAW FUNCTIONS

View file

@ -72,7 +72,7 @@ function Scene:updateEnd(dt)
end end
function Scene:updateWorld(dt) 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) self.world:update(dt)
end end
end end

View file

@ -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

View file

@ -0,0 +1,3 @@
return {
default = require "core.modules.transitions.default"
}

View file

@ -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

View file

@ -130,6 +130,7 @@ function SceneManager:draw()
self.currentScene:draw() self.currentScene:draw()
self.currentScene.menusystem:draw() self.currentScene.menusystem:draw()
self.currentScene:drawEnd() self.currentScene:drawEnd()
self.controller.screen:drawTransition()
end end
self.controller.screen:cease() self.controller.screen:cease()
end end

View file

@ -39,6 +39,27 @@ function ScreenManager:new(controller)
CScreen.setColor(0, 0, 0, 1) CScreen.setColor(0, 0, 0, 1)
love.graphics.setDefaultFilter( "nearest", "nearest", 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 end
function ScreenManager:applySettings() function ScreenManager:applySettings()
@ -55,6 +76,12 @@ function ScreenManager:applySettings()
CScreen.update(width, height) CScreen.update(width, height)
end end
function ScreenManager:update(dt)
if (self.transition ~= nil) then
self.transition:update(dt)
end
end
-- POINTER FUNCTIONS -- POINTER FUNCTIONS
-- Translate the pointer according to the screen coordinates -- Translate the pointer according to the screen coordinates
@ -104,4 +131,10 @@ function ScreenManager:cease()
CScreen.cease() CScreen.cease()
end end
function ScreenManager:drawTransition()
if (self.transition ~= nil) then
self.transition:draw()
end
end
return ScreenManager return ScreenManager

View file

@ -21,7 +21,9 @@ function Charset:new(scene)
end end
function Charset:update(dt) function Charset:update(dt)
if (core.screen:isActive()) then
self.currentFrame = ((self.currentFrame + (dt*5)) % 4) self.currentFrame = ((self.currentFrame + (dt*5)) % 4)
end
end end
function Charset:addChar(ii, jj) function Charset:addChar(ii, jj)