sonic-bluestreak/sonic-bluestreak.love/scenes/overworld/actors/player/health.lua
2021-11-25 10:57:13 +01:00

37 lines
No EOL
1.2 KiB
Lua

local PlayerHealth = Object:extend()
local ComplexHPBar = require "game.modules.gui.complexhpbar"
local HPBAR_SIZE = 80
function PlayerHealth:initHealth()
self.hpbar = ComplexHPBar(HPBAR_SIZE)
self.hpbar:setColorForeground(248/255, 160/255, 0, 1)
self.hpbar:setColorBackground(112/255, 0, 0)
self.fallDamage = 0
self.fallSound = ""
end
function PlayerHealth:drawHealth(x, y)
for i, name in ipairs(game.characters.team) do
local yy = y + (i * 17)
local character = game.characters.list[name]
self.scene.assets.fonts["hudnbrs_small"]:set()
self.hpbar:drawWithLabels(x + 18, yy, character.hp, character.stats:get(character.stats.HPMAX))
self.assets.tileset["charicons"]:drawTile(character.data.icon, x, yy - 3)
end
end
function PlayerHealth:takeDamage(damage)
local damage = damage or 10
damage = damage / 100
if (game.difficulty:get("allDamage")) then
for _, name in ipairs(game.characters.team) do
game.characters:sendDamageFromMap(name, damage)
end
else
game.characters:sendDamageFromMap(game.characters.team[game.characters.active], damage)
end
end
return PlayerHealth