summaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2015-02-04 02:18:22 +0100
committerWuzzy <almikes@aol.com>2015-02-04 02:18:22 +0100
commitf6d660d40f3b8f6ff005efbcce349a0882792da4 (patch)
treedabb86f7733b9a84301640d310ef509b3af9e43c /init.lua
parentc198284de902dd76330b52458c0574c6dd6c2954 (diff)
Use max. 160 pixel wide bars to represent stats
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua31
1 files changed, 10 insertions, 21 deletions
diff --git a/init.lua b/init.lua
index 19e9ade..036ccad 100644
--- a/init.lua
+++ b/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