sonic-bluestreak/sonic-bluestreak.love/scenes/overworld/screens/gameover.lua

90 lines
2.5 KiB
Lua
Raw Permalink Normal View History

2021-11-25 10:57:13 +01:00
local BaseScreen = require "scenes.overworld.screens.parent"
local GameOver = BaseScreen:extend()
local TweenManager = require "birb.classes.time"
local gui = require "game.modules.gui"
local tw, th = 128, 32
local defTransitions = require "birb.modules.transitions"
local ConfirmDialog = require "game.modules.confirmdialog"
function GameOver:new(scene)
GameOver.super.new(self, 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 GameOver: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 GameOver:prepareAnimation()
-- Label
self.tweens:newTween(0, 0.6, {labelOpacity=1}, 'inExpo')
self.tweens:newTween(0.9, 0.4, {labelX=4}, 'inExpo')
self.tweens:newTimer(1.8, "continue")
end
function GameOver:update(dt)
self.tweens:update(dt)
end
function GameOver:draw()
local width, height = core.screen:getDimensions()
self:drawVignette(width, height)
self:drawLabel(width/2, 48, self.labelX, self.labelOpacity)
end
function GameOver:timerResponse(timer)
if (timer == "continue") then
local confirm = ConfirmDialog(self.scene, "Do you want to return to title ? \nYou can also reload your latest save.",
function() self:returnToTitle() end, "Return to title",
function() self:loadLastSave() end, "Reload last save")
confirm.darken = false
end
end
function GameOver:drawVignette(width, height)
love.graphics.setColor(0, 0, 0, self.vignetteOpacity)
love.graphics.rectangle("fill", 0, 0, width, height)
end
function GameOver:drawLabel(x, y, x2, opacity)
love.graphics.setColor(1, 1, 1, opacity)
self.assets.fonts["SA2font"]:print("GAME", x - x2, y, "right")
self.assets.fonts["SA2font"]:print("OVER", x + x2, y, "left")
end
function GameOver:returnToTitle()
core.screen:startTransition(defTransitions.default, defTransitions.circle, function() scenes.menus.title(true) end, 424/2, 240/2)
end
function GameOver:loadLastSave()
self.scene.tweens:newTween(0, 0.3, {borderPosition=0}, "inOutQuad")
core.screen:startTransition(defTransitions.default, defTransitions.default, function() game:reload() scenes.overworld() end, 424/2, 240/2)
end
return GameOver