2020-07-19 16:20:57 +02:00
|
|
|
local SimpleHPBar = Object:extend()
|
|
|
|
|
2021-05-05 11:41:25 +02:00
|
|
|
local TweenManager = require "birb.classes.time"
|
2020-07-19 16:20:57 +02:00
|
|
|
local gui = require "game.modules.gui"
|
|
|
|
|
|
|
|
function SimpleHPBar:new(hp)
|
|
|
|
self.tweens = TweenManager(self)
|
|
|
|
self.hp = hp
|
|
|
|
self.baseHP = hp
|
|
|
|
end
|
|
|
|
|
|
|
|
function SimpleHPBar:setHP(newHP)
|
|
|
|
self.tweens:newTween(0, 0.1, {hp = newHP}, 'inCubic')
|
|
|
|
end
|
|
|
|
|
|
|
|
function SimpleHPBar:update(dt)
|
|
|
|
self.tweens:update(dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
function SimpleHPBar:draw(x, y)
|
|
|
|
love.graphics.setColor(0, 0, 0, 1)
|
|
|
|
gui.drawBar(x, y, 26, 4)
|
2020-08-04 19:53:11 +02:00
|
|
|
love.graphics.rectangle("fill", x, y, 24, 4)
|
2020-07-19 16:20:57 +02:00
|
|
|
love.graphics.setColor(248/255, 160/255, 0, 1)
|
2020-08-04 19:53:11 +02:00
|
|
|
local bar = math.max(0, math.floor(22 * (self.hp / self.baseHP)))
|
|
|
|
love.graphics.rectangle("fill", x + 1, y + 1, math.floor(bar), 2)
|
2020-07-19 16:20:57 +02:00
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
return SimpleHPBar
|