2021-04-18 18:23:52 +02:00
|
|
|
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)
|
2021-04-19 18:04:29 +02:00
|
|
|
self.fallDamage = 0
|
2021-04-21 16:46:41 +02:00
|
|
|
self.fallSound = ""
|
2021-04-18 18:23:52 +02:00
|
|
|
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()
|
2021-07-03 09:51:19 +02:00
|
|
|
self.hpbar:drawWithLabels(x + 18, yy, character.hp, character.stats:get(character.stats.HPMAX))
|
2021-04-18 18:23:52 +02:00
|
|
|
self.assets.tileset["charicons"]:drawTile(character.data.icon, x, yy - 3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-19 18:04:29 +02:00
|
|
|
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
|
|
|
|
|
2021-04-18 18:23:52 +02:00
|
|
|
return PlayerHealth
|