2019-08-16 22:37:43 +02:00
|
|
|
local VictoryScreen = Object:extend()
|
|
|
|
|
|
|
|
local TweenManager = require "game.modules.tweenmanager"
|
|
|
|
|
|
|
|
local BATTLECOMPLETE_START = 2
|
|
|
|
local BATTLECOMPLETE_STOP = 4
|
|
|
|
|
2019-08-31 21:03:17 +02:00
|
|
|
local gui = require "game.modules.gui"
|
|
|
|
|
2020-08-06 19:10:54 +02:00
|
|
|
local charutils = require "game.utils.characters"
|
|
|
|
|
2020-08-06 16:37:06 +02:00
|
|
|
local tw, th = 280+48, 64
|
|
|
|
local rankWidth, rankHeight = 64, 48
|
2019-08-31 21:03:17 +02:00
|
|
|
|
2020-08-06 19:10:54 +02:00
|
|
|
local rankFactor = {1, 1.2, 1.5, 2}
|
|
|
|
|
2019-08-16 22:37:43 +02:00
|
|
|
function VictoryScreen:new(scene)
|
|
|
|
self.scene = scene
|
|
|
|
self.assets = scene.assets
|
2020-08-06 16:37:06 +02:00
|
|
|
self.turnSystem = scene.turns
|
2019-08-16 22:37:43 +02:00
|
|
|
|
2020-08-06 19:10:54 +02:00
|
|
|
self:setVariables()
|
|
|
|
self:getRewards()
|
|
|
|
|
|
|
|
self.infoBox = self:createInfoBox()
|
|
|
|
self.rankBox = gui.newTextBox("assets/gui/dialogbox.png", rankWidth, rankHeight)
|
|
|
|
|
2019-08-16 22:37:43 +02:00
|
|
|
self.tweens = TweenManager(self)
|
2020-08-06 19:10:54 +02:00
|
|
|
self:prepareAnimation()
|
|
|
|
end
|
2019-08-16 22:37:43 +02:00
|
|
|
|
2020-08-06 19:10:54 +02:00
|
|
|
function VictoryScreen:setVariables()
|
|
|
|
-- Vignette Opacity
|
2019-08-16 22:37:43 +02:00
|
|
|
self.vignetteOpacity = 0
|
|
|
|
|
2020-08-06 19:10:54 +02:00
|
|
|
-- Battle FInished Label
|
|
|
|
self.labelOpacity = 0
|
2019-08-16 22:37:43 +02:00
|
|
|
local _, height = core.screen:getDimensions()
|
|
|
|
self.labelY = height/2
|
|
|
|
|
2020-08-06 19:10:54 +02:00
|
|
|
-- Infobox
|
|
|
|
self.tbSize = 0.6
|
|
|
|
self.tbOpacity = 0
|
|
|
|
|
|
|
|
-- Ranks
|
|
|
|
self.rankOpacity = 0
|
|
|
|
self.rankSize = 4
|
|
|
|
|
|
|
|
self.addExp = false
|
|
|
|
|
|
|
|
self.charDone = {}
|
|
|
|
self.nbrCharDone = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function VictoryScreen:prepareAnimation()
|
|
|
|
-- Vignette
|
2019-08-16 22:37:43 +02:00
|
|
|
self.tweens:newTween(0, 0.6, {vignetteOpacity=0.75}, 'inExpo')
|
2020-08-06 19:10:54 +02:00
|
|
|
|
|
|
|
-- Label
|
2019-08-16 22:37:43 +02:00
|
|
|
self.tweens:newTween(0, 0.6, {labelOpacity=1}, 'inExpo')
|
|
|
|
self.tweens:newTween(0.9, 0.4, {labelY=32}, 'inExpo')
|
|
|
|
|
2020-08-06 19:10:54 +02:00
|
|
|
-- Infobox
|
2019-08-31 21:03:17 +02:00
|
|
|
self.tweens:newTween(1.4, 0.4, {tbSize=1, tbOpacity=1}, 'inExpo')
|
2020-08-06 16:37:06 +02:00
|
|
|
|
2020-08-06 19:10:54 +02:00
|
|
|
-- Ranks
|
2020-08-06 16:37:06 +02:00
|
|
|
self.tweens:newTween(1.9, 0.4, {rankSize=1, rankOpacity=1}, 'inExpo')
|
2020-08-06 19:10:54 +02:00
|
|
|
self.tweens:newTween(2.4, 0.3, {shownExp=self.realExp, shownRings=self.realRings}, 'inExpo')
|
|
|
|
self.tweens:newSwitch(2.7, {"addExp"})
|
|
|
|
end
|
|
|
|
|
|
|
|
function VictoryScreen:getRewards()
|
|
|
|
self.rank = self.turnSystem:getRank()
|
|
|
|
|
|
|
|
local exp, rings = self.turnSystem:getRewards()
|
|
|
|
self.shownExp, self.shownRings = exp, rings
|
|
|
|
self.realExp = exp * rankFactor[self.rank]
|
|
|
|
self.realRings = rings * rankFactor[self.rank]
|
|
|
|
|
|
|
|
for i,character in ipairs(self.turnSystem.player.list) do
|
|
|
|
character.targetExp = character.exp + self.realExp
|
|
|
|
end
|
|
|
|
|
|
|
|
game.loot.rings = game.loot.rings + self.realRings
|
2020-08-06 16:37:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function VictoryScreen:createInfoBox()
|
|
|
|
local textBox = gui.newTextBox("assets/gui/dialogbox.png", tw, th)
|
|
|
|
local canvas = love.graphics.newCanvas(tw, th)
|
|
|
|
love.graphics.setCanvas(canvas)
|
|
|
|
love.graphics.draw(textBox, 0, 0)
|
|
|
|
self.assets.fonts["SA2font"]:print("ENNEMIES:", 6, 6)
|
|
|
|
self.assets.fonts["SA2font"]:print(self.turnSystem.ennemies:count(), tw - 6, 6, "right")
|
|
|
|
self.assets.fonts["SA2font"]:print("COMBOS:", 6, th - 6 - 22)
|
|
|
|
self.assets.fonts["SA2font"]:print("0/0", tw - 6, th - 6 - 22, "right")
|
|
|
|
love.graphics.setCanvas()
|
|
|
|
local imagedata = canvas:newImageData()
|
|
|
|
local texture = love.graphics.newImage( imagedata )
|
|
|
|
imagedata:release()
|
|
|
|
canvas:release()
|
|
|
|
|
|
|
|
return texture
|
2019-08-16 22:37:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function VictoryScreen:update(dt)
|
|
|
|
self.tweens:update(dt)
|
2020-08-06 19:10:54 +02:00
|
|
|
|
|
|
|
if ( self.addExp and (not self:allCharDone())) then
|
|
|
|
for i,character in ipairs(self.turnSystem.player.list) do
|
|
|
|
self:addCharacterExp(dt, character)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if (self:allCharDone()) then
|
|
|
|
local keys = self.scene:getKeys(1)
|
|
|
|
if (keys["A"].isPressed) then
|
|
|
|
--placeholder, pour l'instant on retourne juste au menu
|
|
|
|
scenes.debug.menu()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function VictoryScreen:addCharacterExp(dt, character)
|
|
|
|
if (self.charDone[character.name] == "done") then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local level = character.abstract.level
|
|
|
|
local xpAddRatio = charutils.getLevelExpRange(level) * 0.5
|
|
|
|
local newExp = character.exp + (xpAddRatio * dt)
|
|
|
|
|
|
|
|
if (newExp < character.targetExp) then
|
|
|
|
character.exp = newExp
|
|
|
|
local nextLevelExp = charutils.getExpValue(level + 1)
|
|
|
|
if (character.exp >= nextLevelExp) then
|
|
|
|
character.abstract:levelUp()
|
|
|
|
end
|
|
|
|
else
|
|
|
|
character.exp = character.targetExp
|
|
|
|
character.abstract.exp = character.exp
|
|
|
|
self.charDone[character.name] = "done"
|
|
|
|
self.nbrCharDone = self.nbrCharDone + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function VictoryScreen:allCharDone()
|
|
|
|
return (self.nbrCharDone >= self.turnSystem.player:count())
|
2019-08-16 22:37:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function VictoryScreen:draw()
|
2020-08-06 16:37:06 +02:00
|
|
|
local width, height = core.screen:getDimensions()
|
|
|
|
self:drawVignette(width, height)
|
|
|
|
self:drawLabel(width/2, self.labelY, self.labelOpacity)
|
|
|
|
|
|
|
|
self:drawInfobox(width/2, height/2 - 32, self.tbSize, self.tbOpacity)
|
|
|
|
|
|
|
|
local startx = (width/2 - tw/2)
|
|
|
|
local endx = (width/2 + tw/2)
|
|
|
|
local scorex = startx + rankWidth + 8
|
|
|
|
local starty = height/2 + 8
|
|
|
|
local endy = starty + rankHeight
|
|
|
|
|
|
|
|
self:drawRankBox(startx, starty, self.rankSize, self.tbOpacity, self.rankOpacity)
|
2020-08-06 19:10:54 +02:00
|
|
|
self:drawText(scorex, starty, endx, "EXP:", math.floor(self.shownExp), self.tbOpacity)
|
|
|
|
self:drawText(scorex, endy - 24, endx, "RINGS:", math.floor(self.shownRings), self.tbOpacity)
|
2020-08-06 16:37:06 +02:00
|
|
|
|
|
|
|
for i,character in ipairs(self.turnSystem.player.list) do
|
|
|
|
self:drawCharacterExp(startx + ((i-1)*84), endy + 8, character, self.tbOpacity)
|
|
|
|
end
|
|
|
|
|
2020-08-06 19:10:54 +02:00
|
|
|
if (self:allCharDone()) then
|
|
|
|
self.assets.fonts["small"]:print("Press the A key to continue...", width/2, endy + 32, "center")
|
|
|
|
end
|
|
|
|
|
2020-08-06 16:37:06 +02:00
|
|
|
utils.graphics.resetColor()
|
|
|
|
end
|
|
|
|
|
|
|
|
function VictoryScreen:drawVignette(width, height)
|
2019-08-16 22:37:43 +02:00
|
|
|
love.graphics.setColor(0, 0, 0, self.vignetteOpacity)
|
|
|
|
|
|
|
|
love.graphics.rectangle("fill", 0, 0, width, height)
|
2020-08-06 16:37:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function VictoryScreen:drawLabel(x, y, opacity)
|
|
|
|
love.graphics.setColor(1, 1, 1, opacity)
|
2019-08-16 22:37:43 +02:00
|
|
|
|
|
|
|
local w, h = self.assets.images["battlecompleted"]:getDimensions()
|
2020-08-06 16:37:06 +02:00
|
|
|
self.assets.images["battlecompleted"]:draw(x, y, 0, 1, 1, w/2, h/2)
|
|
|
|
end
|
2019-08-31 21:03:17 +02:00
|
|
|
|
2020-08-06 16:37:06 +02:00
|
|
|
function VictoryScreen:drawInfobox(x, y, size, opacity)
|
|
|
|
love.graphics.setColor(1, 1, 1, opacity)
|
|
|
|
love.graphics.draw(self.infoBox, x, y, 0, size, size, tw/2, th/2)
|
|
|
|
end
|
2019-08-31 21:03:17 +02:00
|
|
|
|
2020-08-06 16:37:06 +02:00
|
|
|
function VictoryScreen:drawRankBox(x, y, rankSize, boxOpacity, rankOpacity)
|
|
|
|
love.graphics.setColor(1, 1, 1, boxOpacity)
|
|
|
|
love.graphics.draw(self.rankBox, x, y)
|
|
|
|
love.graphics.setColor(1, 1, 1, rankOpacity)
|
2020-08-06 19:10:54 +02:00
|
|
|
self.assets.tileset["ranks"]:drawTile(self.rank, x + (rankWidth/2), y + (rankHeight/2), 0, rankSize, rankSize, 13, 13)
|
2020-08-06 16:37:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function VictoryScreen:drawText(x, y, x2, text1, text2, opacity)
|
|
|
|
love.graphics.setColor(1, 1, 1, opacity)
|
|
|
|
self.assets.fonts["SA2font"]:print(text1, x, y)
|
|
|
|
self.assets.fonts["SA2font"]:print(text2, x2, y, "right")
|
|
|
|
end
|
|
|
|
|
|
|
|
function VictoryScreen:drawCharacterExp(x, y, character, opacity)
|
|
|
|
love.graphics.setColor(1, 1, 1, opacity)
|
|
|
|
self.assets.images["expbar"]:draw(x, y)
|
|
|
|
character:drawIcon(x+1, y+6)
|
|
|
|
love.graphics.setColor(0, 0.8, 0.1, opacity)
|
2020-08-06 19:10:54 +02:00
|
|
|
local level = character.abstract.level
|
|
|
|
local exp = character.exp
|
|
|
|
local remainingExp = charutils.getRemainingExp(exp, level)
|
|
|
|
local expRatio = charutils.getRelativeExpValue(exp, level) / charutils.getLevelExpRange(level)
|
|
|
|
gui.drawBar(x + 22, y + 11, math.floor(56 * expRatio), 7)
|
|
|
|
love.graphics.setColor(1, 1, 1, opacity)
|
|
|
|
self.assets.fonts["hudnbrs_small"]:print(math.floor(remainingExp), x + 71, y + 11, "right")
|
|
|
|
self.assets.fonts["hudnbrs_small"]:print(level, x + 72, y + 1, "right")
|
2019-08-16 22:37:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return VictoryScreen
|