chore: separate statusbar handling from heroes
This commit is contained in:
parent
84cab7c92a
commit
08ff743754
2 changed files with 86 additions and 38 deletions
|
@ -2,6 +2,7 @@ local Battler = require("scenes.battlesystem.actors.battler")
|
||||||
local Hero = Battler:extend()
|
local Hero = Battler:extend()
|
||||||
|
|
||||||
local gui = require "game.modules.gui"
|
local gui = require "game.modules.gui"
|
||||||
|
local StatusBar = require "scenes.battlesystem.gui.statusbar"
|
||||||
|
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialize the hero
|
-- Initialize the hero
|
||||||
|
@ -18,6 +19,10 @@ function Hero:new(world, x, y, charid, charnumber)
|
||||||
self:initChoregraphySystem()
|
self:initChoregraphySystem()
|
||||||
|
|
||||||
self:initVoices()
|
self:initVoices()
|
||||||
|
|
||||||
|
self.statusbar = StatusBar(self)
|
||||||
|
|
||||||
|
self.side = "heroes"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- CHARACTER FUNCTIONS
|
-- CHARACTER FUNCTIONS
|
||||||
|
@ -48,7 +53,7 @@ function Hero:setHP(value, relative)
|
||||||
end
|
end
|
||||||
|
|
||||||
game.characters.list[self.charid].stats.hp = value
|
game.characters.list[self.charid].stats.hp = value
|
||||||
self.tweens:newTween(0, 0.3, {hp = game.characters.list[self.charid].stats.hp}, 'linear')
|
self.statusbar:updateHP()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:setPP(value, relative)
|
function Hero:setPP(value, relative)
|
||||||
|
@ -57,7 +62,7 @@ function Hero:setPP(value, relative)
|
||||||
end
|
end
|
||||||
|
|
||||||
game.characters.list[self.charid].stats.pp = value
|
game.characters.list[self.charid].stats.pp = value
|
||||||
self.tweens:newTween(0, 0.3, {pp = game.characters.list[self.charid].stats.pp}, 'linear')
|
self.statusbar:updatePP()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,6 +109,8 @@ function Hero:update(dt)
|
||||||
self.xprevious = self.x
|
self.xprevious = self.x
|
||||||
self.yprevious = self.y
|
self.yprevious = self.y
|
||||||
self.zprevious = self.z
|
self.zprevious = self.z
|
||||||
|
|
||||||
|
self.statusbar:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- MOVE FUNCTIONS
|
-- MOVE FUNCTIONS
|
||||||
|
@ -277,7 +284,7 @@ end
|
||||||
|
|
||||||
function Hero:timerResponse(timer)
|
function Hero:timerResponse(timer)
|
||||||
if timer == "switchActiveBattler" then
|
if timer == "switchActiveBattler" then
|
||||||
self.world:switchActiveBattler()
|
self.scene.turns:nextAction()
|
||||||
elseif timer == "wait" then
|
elseif timer == "wait" then
|
||||||
self.choregraphy.changeAction = true
|
self.choregraphy.changeAction = true
|
||||||
elseif timer == "cursorMove" then
|
elseif timer == "cursorMove" then
|
||||||
|
@ -547,41 +554,7 @@ function Hero:drawIcon(x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:drawHUD()
|
function Hero:drawHUD()
|
||||||
local HUDBASE = 8
|
self.statusbar:draw()
|
||||||
local HUDSEP = 152
|
|
||||||
local x = HUDBASE + (self.charnumber-1)*HUDSEP
|
|
||||||
local y = self.world:getPlayerHUDPosition()
|
|
||||||
|
|
||||||
self.assets.images["e_speedster"]:draw(x, y)
|
|
||||||
core.screen:setScissor(x, y-16, 32, 40)
|
|
||||||
self.assets.sprites[self.charid]:drawAnimation(x+14, y+14)
|
|
||||||
core.screen:resetScissor( )
|
|
||||||
self.assets.images["m_speedster"]:draw(x, y)
|
|
||||||
self.assets.images["statusbar"]:draw(x+12, y-6)
|
|
||||||
|
|
||||||
local hpmax = game.characters.list[self.charid].stats.hpmax
|
|
||||||
local ppmax = game.characters.list[self.charid].stats.ppmax
|
|
||||||
|
|
||||||
local bar1 = math.floor((self.hp/hpmax)*107)
|
|
||||||
local bar2 = math.floor((self.pp/ppmax)*108)
|
|
||||||
|
|
||||||
love.graphics.setColor(248/255, 160/255, 0, 1)
|
|
||||||
gui.drawBar(x+29, y+5, bar1, 7)
|
|
||||||
love.graphics.setColor(0, 248/255, 248/255, 1)
|
|
||||||
gui.drawBar(x+17, y+17, bar2, 7)
|
|
||||||
utils.graphics.resetColor()
|
|
||||||
|
|
||||||
self.assets.fonts["hudnbrs_small"]:set()
|
|
||||||
love.graphics.print(math.floor(self.hp) .. "/" .. hpmax, x+34, y+5)
|
|
||||||
love.graphics.print(math.floor(self.pp) .. "/" .. ppmax, x+28, y+17)
|
|
||||||
|
|
||||||
local lvl = game.characters.list[self.charid].stats.level
|
|
||||||
|
|
||||||
if lvl < 100 then
|
|
||||||
lvl = "0" .. lvl
|
|
||||||
end
|
|
||||||
|
|
||||||
love.graphics.print(lvl, x+122, y-5)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Hero
|
return Hero
|
||||||
|
|
75
sonic-radiance.love/scenes/battlesystem/gui/statusbar.lua
Normal file
75
sonic-radiance.love/scenes/battlesystem/gui/statusbar.lua
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
local StatusBar = Object:extend()
|
||||||
|
local TweenManager = require "game.modules.tweenmanager"
|
||||||
|
|
||||||
|
local gui = require "game.modules.gui"
|
||||||
|
|
||||||
|
local HUDBASE = 8
|
||||||
|
local HUDSEP = 152
|
||||||
|
|
||||||
|
function StatusBar:new(actor)
|
||||||
|
self.actor = actor
|
||||||
|
self.hud = self.actor.scene.hud
|
||||||
|
self.assets = self.actor.assets
|
||||||
|
|
||||||
|
self.charid = self.actor.charid
|
||||||
|
self.stats = game.characters.list[self.charid].stats
|
||||||
|
|
||||||
|
self.hp = self.stats.hp
|
||||||
|
self.pp = self.stats.pp
|
||||||
|
|
||||||
|
self.tweens = TweenManager(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function StatusBar:update(dt)
|
||||||
|
self.tweens:update(dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
function StatusBar:updateHP()
|
||||||
|
self.tweens:newTween(0, 0.3, {hp = game.characters.list[self.charid].stats.hp}, 'linear')
|
||||||
|
end
|
||||||
|
|
||||||
|
function StatusBar:updatePP()
|
||||||
|
self.tweens:newTween(0, 0.3, {pp = game.characters.list[self.charid].stats.pp}, 'linear')
|
||||||
|
end
|
||||||
|
|
||||||
|
function StatusBar:drawEmblem(x, y)
|
||||||
|
self.assets.images["e_speedster"]:draw(x, y)
|
||||||
|
core.screen:setScissor(x, y-16, 32, 40)
|
||||||
|
self.assets.sprites[self.charid]:drawAnimation(x+14, y+14)
|
||||||
|
core.screen:resetScissor( )
|
||||||
|
self.assets.images["m_speedster"]:draw(x, y)
|
||||||
|
end
|
||||||
|
|
||||||
|
function StatusBar:draw()
|
||||||
|
local x = HUDBASE + (self.actor.charnumber-1)*HUDSEP
|
||||||
|
local y = self.actor.scene.hud:getPlayerHUDPosition()
|
||||||
|
|
||||||
|
self:drawEmblem(x, y)
|
||||||
|
self.assets.images["statusbar"]:draw(x+12, y-6)
|
||||||
|
|
||||||
|
local hpmax = self.stats.hpmax
|
||||||
|
local ppmax = self.stats.ppmax
|
||||||
|
|
||||||
|
local bar1 = math.floor((self.hp/self.stats.hpmax)*107)
|
||||||
|
local bar2 = math.floor((self.pp/self.stats.ppmax)*108)
|
||||||
|
|
||||||
|
love.graphics.setColor(248/255, 160/255, 0, 1)
|
||||||
|
gui.drawBar(x+29, y+5, bar1, 7)
|
||||||
|
love.graphics.setColor(0, 248/255, 248/255, 1)
|
||||||
|
gui.drawBar(x+17, y+17, bar2, 7)
|
||||||
|
utils.graphics.resetColor()
|
||||||
|
|
||||||
|
self.assets.fonts["hudnbrs_small"]:set()
|
||||||
|
love.graphics.print(math.floor(self.hp) .. "/" .. hpmax, x+34, y+5)
|
||||||
|
love.graphics.print(math.floor(self.pp) .. "/" .. ppmax, x+28, y+17)
|
||||||
|
|
||||||
|
local lvl = game.characters.list[self.charid].stats.level
|
||||||
|
|
||||||
|
if lvl < 100 then
|
||||||
|
lvl = "0" .. lvl
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.print(lvl, x+122, y-5)
|
||||||
|
end
|
||||||
|
|
||||||
|
return StatusBar
|
Loading…
Reference in a new issue