Use max. 160 pixel wide bars to represent stats
31
init.lua
@ -11,7 +11,7 @@ local air_hud = {}
|
||||
-- default settings
|
||||
|
||||
HUD_SCALEABLE = false
|
||||
HUD_SIZE = ""
|
||||
HUD_BARLENGTH = 160
|
||||
|
||||
-- statbar positions
|
||||
HUD_HEALTH_POS = {x=0.5,y=0.9}
|
||||
@ -22,7 +22,6 @@ HUD_AIR_OFFSET = {x=15,y=2}
|
||||
-- dirty way to check for new statbars
|
||||
if dump(minetest.hud_replace_builtin) ~= "nil" then
|
||||
HUD_SCALEABLE = true
|
||||
HUD_SIZE = {x=24, y=24}
|
||||
HUD_HEALTH_POS = {x=0.5,y=1}
|
||||
HUD_HEALTH_OFFSET = {x=-262, y=-87}
|
||||
HUD_AIR_POS = {x=0.5,y=1}
|
||||
@ -31,7 +30,9 @@ end
|
||||
|
||||
HUD_TICK = 0.1
|
||||
|
||||
|
||||
function hud.value_to_barlength(value, max)
|
||||
return math.ceil((value/max) * HUD_BARLENGTH)
|
||||
end
|
||||
|
||||
--load custom settings
|
||||
local set = io.open(minetest.get_modpath("hudbars").."/hud.conf", "r")
|
||||
@ -56,21 +57,11 @@ local function custom_hud(player)
|
||||
|
||||
if minetest.setting_getbool("enable_damage") then
|
||||
--health
|
||||
player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HEALTH_POS,
|
||||
size = HUD_SIZE,
|
||||
text = "hud_heart_bg.png",
|
||||
number = 20,
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_HEALTH_OFFSET,
|
||||
})
|
||||
health_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HEALTH_POS,
|
||||
size = HUD_SIZE,
|
||||
text = "hud_heart_fg.png",
|
||||
number = player:get_hp(),
|
||||
text = "hudbars_bar_health.png",
|
||||
number = hud.value_to_barlength(player:get_hp(), 20),
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_HEALTH_OFFSET,
|
||||
})
|
||||
@ -79,9 +70,8 @@ local function custom_hud(player)
|
||||
air_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_AIR_POS,
|
||||
size = HUD_SIZE,
|
||||
text = "hud_air_fg.png",
|
||||
number = 0,
|
||||
text = "hudbars_bar_breath.png",
|
||||
number = hud.value_to_barlength(math.min(player:get_breath(), 10), 10),
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_AIR_OFFSET,
|
||||
})
|
||||
@ -98,15 +88,14 @@ local function update_hud(player)
|
||||
if player:get_breath() ~= air then
|
||||
air = player:get_breath()
|
||||
hud.air[name] = air
|
||||
if air > 10 then air = 0 end
|
||||
player:hud_change(air_hud[name], "number", air*2)
|
||||
player:hud_change(air_hud[name], "number", hud.value_to_barlength(math.min(air, 10), 10))
|
||||
end
|
||||
--health
|
||||
local hp = tonumber(hud.health[name])
|
||||
if player:get_hp() ~= hp then
|
||||
hp = player:get_hp()
|
||||
hud.health[name] = hp
|
||||
player:hud_change(health_hud[name], "number", hp)
|
||||
player:hud_change(health_hud[name], "number", hud.value_to_barlength(hp, 20))
|
||||
end
|
||||
end
|
||||
|
||||
|
Before Width: | Height: | Size: 579 B |
Before Width: | Height: | Size: 302 B |
Before Width: | Height: | Size: 369 B |
BIN
textures/hudbars_bar_breath.png
Normal file
After Width: | Height: | Size: 80 B |
BIN
textures/hudbars_bar_health.png
Normal file
After Width: | Height: | Size: 80 B |
BIN
textures/hudbars_icon_breath.png
Normal file
After Width: | Height: | Size: 544 B |
BIN
textures/hudbars_icon_health.png
Normal file
After Width: | Height: | Size: 321 B |