feat: finish victory screen

Fix #11
This commit is contained in:
Kazhnuz 2020-08-06 19:10:54 +02:00
parent d9237b9383
commit 697426f4d1
4 changed files with 141 additions and 17 deletions

View file

@ -31,6 +31,18 @@ function CharUtils.getExpValue(level)
return math.floor( ( CONST.EXP_MULTIPLICATOR * ( level ^ 3 ) ) / CONST.EXP_RATIO ) return math.floor( ( CONST.EXP_MULTIPLICATOR * ( level ^ 3 ) ) / CONST.EXP_RATIO )
end end
function CharUtils.getRelativeExpValue(exp, level)
return exp - CharUtils.getExpValue(level)
end
function CharUtils.getLevelExpRange(level)
return CharUtils.getExpValue(level + 1) - CharUtils.getExpValue(level)
end
function CharUtils.getRemainingExp(exp, level)
return CharUtils.getExpValue(level + 1) - exp
end
function CharUtils.getStatValue(level, base) function CharUtils.getStatValue(level, base)
return math.floor( (((base * CONST.MULT_STAT) * level)/100) ) + CONST.BASE_STAT return math.floor( (((base * CONST.MULT_STAT) * level)/100) ) + CONST.BASE_STAT
end end

View file

@ -19,6 +19,7 @@ function HeroFighter:new(owner, character, id)
self:initVoices() self:initVoices()
self.selection = nil self.selection = nil
self.exp = self.abstract.exp
end end
function HeroFighter:updateAssets(dt) function HeroFighter:updateAssets(dt)

View file

@ -57,6 +57,19 @@ function TurnController:update(dt)
end end
end end
function TurnController:getRank()
return 3
end
function TurnController:getRewards()
local exp, ring = 0, 0
for i, ennemy in ipairs(self.ennemies.list) do
exp = exp + ennemy.abstract.data.giveExp
ring = ring + ennemy.abstract.data.giveRings
end
return exp, ring
end
function TurnController:nextAction() function TurnController:nextAction()
if (self.turns.isFinished) or (self.turns.current >= #self.actionList) then if (self.turns.isFinished) or (self.turns.current >= #self.actionList) then
self:startNewTurn() self:startNewTurn()

View file

@ -7,36 +7,81 @@ local BATTLECOMPLETE_STOP = 4
local gui = require "game.modules.gui" local gui = require "game.modules.gui"
local charutils = require "game.utils.characters"
local tw, th = 280+48, 64 local tw, th = 280+48, 64
local rankWidth, rankHeight = 64, 48 local rankWidth, rankHeight = 64, 48
local rankFactor = {1, 1.2, 1.5, 2}
function VictoryScreen:new(scene) function VictoryScreen:new(scene)
self.scene = scene self.scene = scene
self.assets = scene.assets self.assets = scene.assets
self.turnSystem = scene.turns self.turnSystem = scene.turns
self.tweens = TweenManager(self) self:setVariables()
self:getRewards()
self.vignetteOpacity = 0
self.labelOpacity = 0
local _, height = core.screen:getDimensions()
self.labelY = height/2
self.tweens:newTween(0, 0.6, {vignetteOpacity=0.75}, 'inExpo')
self.tweens:newTween(0, 0.6, {labelOpacity=1}, 'inExpo')
self.tweens:newTween(0.9, 0.4, {labelY=32}, 'inExpo')
self.infoBox = self:createInfoBox() self.infoBox = self:createInfoBox()
self.rankBox = gui.newTextBox("assets/gui/dialogbox.png", rankWidth, rankHeight) self.rankBox = gui.newTextBox("assets/gui/dialogbox.png", rankWidth, rankHeight)
self.tweens = TweenManager(self)
self:prepareAnimation()
end
function VictoryScreen:setVariables()
-- Vignette Opacity
self.vignetteOpacity = 0
-- Battle FInished Label
self.labelOpacity = 0
local _, height = core.screen:getDimensions()
self.labelY = height/2
-- Infobox
self.tbSize = 0.6 self.tbSize = 0.6
self.tbOpacity = 0 self.tbOpacity = 0
self.tweens:newTween(1.4, 0.4, {tbSize=1, tbOpacity=1}, 'inExpo') -- Ranks
self.rankOpacity = 0 self.rankOpacity = 0
self.rankSize = 4 self.rankSize = 4
self.addExp = false
self.charDone = {}
self.nbrCharDone = 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, {labelY=32}, 'inExpo')
-- Infobox
self.tweens:newTween(1.4, 0.4, {tbSize=1, tbOpacity=1}, 'inExpo')
-- Ranks
self.tweens:newTween(1.9, 0.4, {rankSize=1, rankOpacity=1}, 'inExpo') self.tweens:newTween(1.9, 0.4, {rankSize=1, rankOpacity=1}, 'inExpo')
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
end end
function VictoryScreen:createInfoBox() function VictoryScreen:createInfoBox()
@ -59,6 +104,48 @@ end
function VictoryScreen:update(dt) function VictoryScreen:update(dt)
self.tweens:update(dt) self.tweens:update(dt)
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())
end end
function VictoryScreen:draw() function VictoryScreen:draw()
@ -75,13 +162,17 @@ function VictoryScreen:draw()
local endy = starty + rankHeight local endy = starty + rankHeight
self:drawRankBox(startx, starty, self.rankSize, self.tbOpacity, self.rankOpacity) self:drawRankBox(startx, starty, self.rankSize, self.tbOpacity, self.rankOpacity)
self:drawText(scorex, starty, endx, "EXP:", "+999", self.tbOpacity) self:drawText(scorex, starty, endx, "EXP:", math.floor(self.shownExp), self.tbOpacity)
self:drawText(scorex, endy - 24, endx, "RINGS:", "+999", self.tbOpacity) self:drawText(scorex, endy - 24, endx, "RINGS:", math.floor(self.shownRings), self.tbOpacity)
for i,character in ipairs(self.turnSystem.player.list) do for i,character in ipairs(self.turnSystem.player.list) do
self:drawCharacterExp(startx + ((i-1)*84), endy + 8, character, self.tbOpacity) self:drawCharacterExp(startx + ((i-1)*84), endy + 8, character, self.tbOpacity)
end end
if (self:allCharDone()) then
self.assets.fonts["small"]:print("Press the A key to continue...", width/2, endy + 32, "center")
end
utils.graphics.resetColor() utils.graphics.resetColor()
end end
@ -107,7 +198,7 @@ function VictoryScreen:drawRankBox(x, y, rankSize, boxOpacity, rankOpacity)
love.graphics.setColor(1, 1, 1, boxOpacity) love.graphics.setColor(1, 1, 1, boxOpacity)
love.graphics.draw(self.rankBox, x, y) love.graphics.draw(self.rankBox, x, y)
love.graphics.setColor(1, 1, 1, rankOpacity) love.graphics.setColor(1, 1, 1, rankOpacity)
self.assets.tileset["ranks"]:drawTile(1, x + (rankWidth/2), y + (rankHeight/2), 0, rankSize, rankSize, 13, 13) self.assets.tileset["ranks"]:drawTile(self.rank, x + (rankWidth/2), y + (rankHeight/2), 0, rankSize, rankSize, 13, 13)
end end
function VictoryScreen:drawText(x, y, x2, text1, text2, opacity) function VictoryScreen:drawText(x, y, x2, text1, text2, opacity)
@ -121,7 +212,14 @@ function VictoryScreen:drawCharacterExp(x, y, character, opacity)
self.assets.images["expbar"]:draw(x, y) self.assets.images["expbar"]:draw(x, y)
character:drawIcon(x+1, y+6) character:drawIcon(x+1, y+6)
love.graphics.setColor(0, 0.8, 0.1, opacity) love.graphics.setColor(0, 0.8, 0.1, opacity)
gui.drawBar(x + 22, y + 11, 56, 7) 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")
end end
return VictoryScreen return VictoryScreen