sonic-radiance/sonic-radiance.love/scenes/battlesystem/gui/screens/gameover.lua
2021-08-15 17:41:39 +02:00

113 lines
3 KiB
Lua

local VictoryScreen = Object:extend()
local TweenManager = require "birb.classes.time"
local ConfirmDialog = require "game.modules.confirmdialog"
local defTransitions = require "birb.modules.transitions"
local radTransitions = require "game.modules.transitions"
local gui = require "game.modules.gui"
local tw, th = 128, 32
function VictoryScreen:new(scene)
self.scene = scene
self.assets = scene.assets
self.turnSystem = scene.turns
self:setVariables()
self.continueBox = gui.newTextBox("assets/gui/dialogbox.png", tw, th)
self.tweens = TweenManager(self)
self:prepareAnimation()
end
function VictoryScreen:setVariables()
-- Vignette Opacity
self.vignetteOpacity = 0
-- Battle FInished Label
self.labelOpacity = 0
local width, height = core.screen:getDimensions()
self.labelX = width/2
-- Infobox
self.tbSize = 0.6
self.tbOpacity = 0
end
function VictoryScreen:prepareAnimation()
-- Vignette
self.tweens:newTween(0, 0.6, {vignetteOpacity=0.75}, 'inExpo')
-- Label
self.tweens:newTween(0, 0.6, {labelOpacity=1}, 'inExpo')
self.tweens:newTween(0.9, 0.4, {labelX=4}, 'inExpo')
-- Infobox
self.tweens:newTween(1.4, 0.4, {tbSize=1, tbOpacity=1}, 'inExpo')
self.tweens:newTimer(1.8, "continue")
end
function VictoryScreen:update(dt)
self.tweens:update(dt)
if (self.continue) then
local keys = self.scene:getKeys(1)
if (keys["left"].isPressed) then
self.continueValue = -1
end
if (keys["right"].isPressed) then
self.continueValue = 1
end
if (keys["A"].isPressed) then
--placeholder, pour l'instant on retourne juste au menu
scenes.menus.main()
end
end
end
function VictoryScreen:draw()
local width, height = core.screen:getDimensions()
self:drawVignette(width, height)
self:drawLabel(width/2, height/4, self.labelX, self.labelOpacity)
end
function VictoryScreen:timerResponse(timer)
if (timer == "continue") then
local confirm = ConfirmDialog(self.scene, "Do you want to continue ?",
function() self:toOverworld() end, "Yes",
function() self:toTitleScreen() end, "No")
confirm.darken = false
end
end
function VictoryScreen:drawVignette(width, height)
love.graphics.setColor(0, 0, 0, self.vignetteOpacity)
love.graphics.rectangle("fill", 0, 0, width, height)
end
function VictoryScreen:toOverworld()
core.screen:startTransition(radTransitions.borders, defTransitions.default, function()
game:reload()
scenes.overworld()
end, 424/2, 240/2)
end
function VictoryScreen:toTitleScreen()
core.screen:startTransition(radTransitions.borders, radTransitions.borders, function() scenes.menus.title(false) end, 424/2, 240/2)
end
function VictoryScreen:drawLabel(x, y, x2, opacity)
love.graphics.setColor(1, 1, 1, opacity)
local w, h = self.assets.images["game"]:getDimensions()
self.assets.images["game"]:draw(x - x2, y, 0, 1, 1, w, h/2)
self.assets.images["over"]:draw(x + x2, y, 0, 1, 1, 0, h/2)
end
return VictoryScreen