diff options
author | Wuzzy <almikes@aol.com> | 2015-02-04 02:18:22 +0100 |
---|---|---|
committer | Wuzzy <almikes@aol.com> | 2015-02-04 02:18:22 +0100 |
commit | f6d660d40f3b8f6ff005efbcce349a0882792da4 (patch) | |
tree | dabb86f7733b9a84301640d310ef509b3af9e43c | |
parent | c198284de902dd76330b52458c0574c6dd6c2954 (diff) |
Use max. 160 pixel wide bars to represent stats
-rw-r--r-- | init.lua | 31 | ||||
-rw-r--r-- | textures/hud_air_fg.png | bin | 579 -> 0 bytes | |||
-rw-r--r-- | textures/hud_heart_bg.png | bin | 302 -> 0 bytes | |||
-rw-r--r-- | textures/hud_heart_fg.png | bin | 369 -> 0 bytes | |||
-rw-r--r-- | textures/hudbars_bar_breath.png | bin | 0 -> 80 bytes | |||
-rw-r--r-- | textures/hudbars_bar_health.png | bin | 0 -> 80 bytes | |||
-rw-r--r-- | textures/hudbars_icon_breath.png | bin | 0 -> 544 bytes | |||
-rw-r--r-- | textures/hudbars_icon_health.png | bin | 0 -> 321 bytes |
8 files changed, 10 insertions, 21 deletions
@@ -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 Binary files differdeleted file mode 100644 index b62c9b0..0000000 --- a/textures/hud_air_fg.png +++ /dev/null diff --git a/textures/hud_heart_bg.png b/textures/hud_heart_bg.png Binary files differdeleted file mode 100644 index e2be276..0000000 --- a/textures/hud_heart_bg.png +++ /dev/null diff --git a/textures/hud_heart_fg.png b/textures/hud_heart_fg.png Binary files differdeleted file mode 100644 index dc213d8..0000000 --- a/textures/hud_heart_fg.png +++ /dev/null diff --git a/textures/hudbars_bar_breath.png b/textures/hudbars_bar_breath.png Binary files differnew file mode 100644 index 0000000..171492c --- /dev/null +++ b/textures/hudbars_bar_breath.png diff --git a/textures/hudbars_bar_health.png b/textures/hudbars_bar_health.png Binary files differnew file mode 100644 index 0000000..6530916 --- /dev/null +++ b/textures/hudbars_bar_health.png diff --git a/textures/hudbars_icon_breath.png b/textures/hudbars_icon_breath.png Binary files differnew file mode 100644 index 0000000..f48aa35 --- /dev/null +++ b/textures/hudbars_icon_breath.png diff --git a/textures/hudbars_icon_health.png b/textures/hudbars_icon_health.png Binary files differnew file mode 100644 index 0000000..941e973 --- /dev/null +++ b/textures/hudbars_icon_health.png |