sonic-radiance/sonic-radiance.love/game/modules/gui/statusbar.lua

67 lines
1.6 KiB
Lua
Raw Normal View History

local StatusBar = Object:extend()
local TweenManager = require "game.modules.tweenmanager"
2020-08-03 09:34:23 +02:00
local gui = require "game.modules.gui"
2020-08-03 09:34:23 +02:00
local Emblem = require "game.modules.gui.emblem"
function StatusBar:new(abstract, scene)
self.assets = scene.assets
self.abstract = abstract
2020-08-03 09:34:23 +02:00
self.emblem = Emblem(abstract, scene)
self.hp = self.abstract.hp
self.pp = self.abstract.pp
2020-08-03 09:34:23 +02:00
self.stats = self.abstract:getStats()
self.tweens = TweenManager(self)
end
function StatusBar:update(dt)
self.tweens:update(dt)
end
function StatusBar:updateHP()
self.tweens:newTween(0, 0.3, {hp = self.abstract.hp}, 'linear')
end
function StatusBar:updatePP()
self.tweens:newTween(0, 0.3, {pp = self.abstract.pp}, 'linear')
end
function StatusBar:draw(x, y)
2020-08-04 19:53:11 +02:00
self.emblem:drawBackground(x, y)
self:drawStatusArea(x+10, y-8)
self.emblem:drawForeground(x, y)
end
2020-08-04 19:53:11 +02:00
function StatusBar:drawStatusArea(x, y)
self.assets.images["statusbar"]:draw(x, y)
2020-08-04 19:53:11 +02:00
local hpmax = self.stats.hpmax
local ppmax = self.stats.ppmax
2020-08-04 19:53:11 +02:00
local bar1 = math.floor((self.hp/self.stats.hpmax)*58)
local bar2 = math.floor((self.pp/self.stats.ppmax)*58)
2020-08-04 19:53:11 +02:00
love.graphics.setColor(248/255, 160/255, 0, 1)
gui.drawBar(x+10, y+11, bar1, 7)
love.graphics.setColor(0, 248/255, 248/255, 1)
gui.drawBar(x+22, y+23, bar2, 7)
utils.graphics.resetColor()
2020-08-04 19:53:11 +02:00
self.assets.fonts["hudnbrs_small"]:set()
love.graphics.print(math.floor(self.hp) .. "/" .. hpmax, x+16, y+11)
love.graphics.print(math.floor(self.pp) .. "/" .. ppmax, x+32, y+23)
2020-08-04 19:53:11 +02:00
local lvl = self.abstract.level
2020-08-04 19:53:11 +02:00
if lvl < 100 then
lvl = "0" .. lvl
end
love.graphics.print(lvl, x+42, y+1)
end
return StatusBar