Skip to content

Commit

Permalink
Show one heart per 2 player hp
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWolfHT committed Aug 12, 2024
1 parent c65d63d commit 14c4226
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions builtin/game/hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,21 @@ core.register_playerevent(player_event_handler)
local enable_damage = core.settings:get_bool("enable_damage")

local function scale_to_hud_max(player, field)
-- Scale "hp" or "breath" to the hud maximum dimensions
local current = player["get_" .. field](player)
local nominal
if field == "hp" then -- HUD is called health but field is hp
nominal = registered_elements.health.elem_def.item

if field == "hp" then
return current
else
nominal = registered_elements[field].elem_def.item
-- Scale "hp" or "breath" to the hud maximum dimensions
local nominal
if field == "hp" then -- HUD is called health but field is hp
nominal = registered_elements.health.elem_def.item
else
nominal = registered_elements[field].elem_def.item
end
local max_display = math.max(player:get_properties()[field .. "_max"], current)
return math.ceil(current / max_display * nominal)
end
local max_display = math.max(player:get_properties()[field .. "_max"], current)
return math.ceil(current / max_display * nominal)
end

register_builtin_hud_element("health", {
Expand Down

0 comments on commit 14c4226

Please sign in to comment.