summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.lua31
-rw-r--r--textures/hud_air_fg.pngbin579 -> 0 bytes
-rw-r--r--textures/hud_heart_bg.pngbin302 -> 0 bytes
-rw-r--r--textures/hud_heart_fg.pngbin369 -> 0 bytes
-rw-r--r--textures/hudbars_bar_breath.pngbin0 -> 80 bytes
-rw-r--r--textures/hudbars_bar_health.pngbin0 -> 80 bytes
-rw-r--r--textures/hudbars_icon_breath.pngbin0 -> 544 bytes
-rw-r--r--textures/hudbars_icon_health.pngbin0 -> 321 bytes
8 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
diff --git a/textures/hud_air_fg.png b/textures/hud_air_fg.png
deleted file mode 100644
index b62c9b0..0000000
--- a/textures/hud_air_fg.png
+++ /dev/null
Binary files differ
diff --git a/textures/hud_heart_bg.png b/textures/hud_heart_bg.png
deleted file mode 100644
index e2be276..0000000
--- a/textures/hud_heart_bg.png
+++ /dev/null
Binary files differ
diff --git a/textures/hud_heart_fg.png b/textures/hud_heart_fg.png
deleted file mode 100644
index dc213d8..0000000
--- a/textures/hud_heart_fg.png
+++ /dev/null
Binary files differ
diff --git a/textures/hudbars_bar_breath.png b/textures/hudbars_bar_breath.png
new file mode 100644
index 0000000..171492c
--- /dev/null
+++ b/textures/hudbars_bar_breath.png
Binary files differ
diff --git a/textures/hudbars_bar_health.png b/textures/hudbars_bar_health.png
new file mode 100644
index 0000000..6530916
--- /dev/null
+++ b/textures/hudbars_bar_health.png
Binary files differ
diff --git a/textures/hudbars_icon_breath.png b/textures/hudbars_icon_breath.png
new file mode 100644
index 0000000..f48aa35
--- /dev/null
+++ b/textures/hudbars_icon_breath.png
Binary files differ
diff --git a/textures/hudbars_icon_health.png b/textures/hudbars_icon_health.png
new file mode 100644
index 0000000..941e973
--- /dev/null
+++ b/textures/hudbars_icon_health.png
Binary files differ