improvement: harmonize game over screens

This commit is contained in:
Kazhnuz 2021-08-15 20:37:12 +02:00
parent 44f2bae574
commit ff752b3c02
2 changed files with 35 additions and 72 deletions

View file

@ -1,4 +1,4 @@
local VictoryScreen = Object:extend()
local GameOverScreen = Object:extend()
local TweenManager = require "birb.classes.time"
local ConfirmDialog = require "game.modules.confirmdialog"
@ -10,7 +10,7 @@ local gui = require "game.modules.gui"
local tw, th = 128, 32
function VictoryScreen:new(scene)
function GameOverScreen:new(scene)
self.scene = scene
self.assets = scene.assets
self.turnSystem = scene.turns
@ -23,7 +23,7 @@ function VictoryScreen:new(scene)
self:prepareAnimation()
end
function VictoryScreen:setVariables()
function GameOverScreen:setVariables()
-- Vignette Opacity
self.vignetteOpacity = 0
@ -37,7 +37,7 @@ function VictoryScreen:setVariables()
self.tbOpacity = 0
end
function VictoryScreen:prepareAnimation()
function GameOverScreen:prepareAnimation()
-- Vignette
self.tweens:newTween(0, 0.6, {vignetteOpacity=0.75}, 'inExpo')
@ -45,69 +45,47 @@ function VictoryScreen:prepareAnimation()
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)
function GameOverScreen: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()
function GameOverScreen:draw()
local width, height = core.screen:getDimensions()
self:drawVignette(width, height)
self:drawLabel(width/2, height/4, self.labelX, self.labelOpacity)
self:drawLabel(width/2, 48, self.labelX, self.labelOpacity)
end
function VictoryScreen:timerResponse(timer)
function GameOverScreen: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")
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 VictoryScreen:drawVignette(width, height)
function GameOverScreen: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)
function GameOverScreen: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)
self.assets.fonts["SA2font"]:print("GAME", x - x2, y, "right")
self.assets.fonts["SA2font"]:print("OVER", x + x2, y, "left")
end
return VictoryScreen
function GameOverScreen:returnToTitle()
core.screen:startTransition(defTransitions.default, defTransitions.circle, function() scenes.menus.title(true) end, 424/2, 240/2)
end
function GameOverScreen: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 GameOverScreen

View file

@ -6,11 +6,8 @@ local TweenManager = require "birb.classes.time"
local gui = require "game.modules.gui"
local tw, th = 128, 32
local ConfirmDialog = require "game.modules.confirmdialog"
local defTransitions = require "birb.modules.transitions"
local radTransitions = require "game.modules.transitions"
local ConfirmDialog = require "game.modules.confirmdialog"
function GameOver:new(scene)
@ -38,9 +35,6 @@ function GameOver:setVariables()
-- Infobox
self.tbSize = 0.6
self.tbOpacity = 0
self.continue = false
self.continueValue = -1
end
function GameOver:prepareAnimation()
@ -48,15 +42,21 @@ function GameOver:prepareAnimation()
self.tweens:newTween(0, 0.6, {labelOpacity=1}, 'inExpo')
self.tweens:newTween(0.9, 0.4, {labelX=4}, 'inExpo')
self.tweens:newSwitch(1.8, {"continue"})
self.tweens:newTimer(1.8, "continue")
end
function GameOver:update(dt)
self.tweens:update(dt)
end
if (self.continue) then
self.continue = false
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")
@ -64,11 +64,6 @@ function GameOver:update(dt)
end
end
function GameOver:draw()
local width, height = core.screen:getDimensions()
self:drawLabel(width/2, 48, self.labelX, self.labelOpacity)
end
function GameOver:drawVignette(width, height)
love.graphics.setColor(0, 0, 0, self.vignetteOpacity)
@ -82,20 +77,10 @@ function GameOver:drawLabel(x, y, x2, opacity)
self.assets.fonts["SA2font"]:print("OVER", x + x2, y, "left")
end
function GameOver:drawContinueBox(x, y, continueValue, size, opacity)
love.graphics.setColor(1, 1, 1, opacity)
love.graphics.draw(self.continueBox, x, y, 0, size, size, tw/2, th/2)
local text = "continue"
if (continueValue == 1) then
text = "quit"
end
self.assets.images["arrow"]:draw(x - continueValue*64, y, math.rad(-90) * continueValue, continueValue, 1, 13, 13)
self.assets.fonts["SA2font"]:print(text, x, y-13, "center")
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)