aboutsummaryrefslogtreecommitdiff
path: root/builtin/game
diff options
context:
space:
mode:
authorANAND <ClobberXD@gmail.com>2020-04-28 23:00:57 +0530
committerGitHub <noreply@github.com>2020-04-28 19:30:57 +0200
commita36c9c3e930608386b983ea76158793fe9d622f6 (patch)
treec6dcb31ce396943bd0127e3e43166258732bc6a8 /builtin/game
parenta368e7e79303fa02ef97580a2c387dcee57bc3c4 (diff)
downloadminetest-a36c9c3e930608386b983ea76158793fe9d622f6.tar.gz
minetest-a36c9c3e930608386b983ea76158793fe9d622f6.tar.bz2
minetest-a36c9c3e930608386b983ea76158793fe9d622f6.zip
Fix breath_bar scaling; delay breath_bar hiding by one second (#8271)
PLAYER_MAX_BREATH_DEFAULT was earlier set to 11, so that 10 bubbles are shown before the breath bar disappears. Now, PLAYER_MAX_BREATH_DEFAULT is set to 10, and the breath_bar scaling code in builtin has been tweaked to show all 10 bubbles before hiding the breath_bar
Diffstat (limited to 'builtin/game')
-rw-r--r--builtin/game/constants.lua2
-rw-r--r--builtin/game/statbars.lua36
2 files changed, 24 insertions, 14 deletions
diff --git a/builtin/game/constants.lua b/builtin/game/constants.lua
index 0ee2a7237..54eeea50f 100644
--- a/builtin/game/constants.lua
+++ b/builtin/game/constants.lua
@@ -24,7 +24,7 @@ core.MAP_BLOCKSIZE = 16
-- Default maximal HP of a player
core.PLAYER_MAX_HP_DEFAULT = 20
-- Default maximal breath of a player
-core.PLAYER_MAX_BREATH_DEFAULT = 11
+core.PLAYER_MAX_BREATH_DEFAULT = 10
-- light.h
-- Maximum value for node 'light_source' parameter
diff --git a/builtin/game/statbars.lua b/builtin/game/statbars.lua
index 46c947b60..6b5b54428 100644
--- a/builtin/game/statbars.lua
+++ b/builtin/game/statbars.lua
@@ -3,22 +3,22 @@ local enable_damage = core.settings:get_bool("enable_damage")
local health_bar_definition = {
hud_elem_type = "statbar",
- position = { x=0.5, y=1 },
+ position = {x = 0.5, y = 1},
text = "heart.png",
number = core.PLAYER_MAX_HP_DEFAULT,
direction = 0,
- size = { x=24, y=24 },
- offset = { x=(-10*24)-25, y=-(48+24+16)},
+ size = {x = 24, y = 24},
+ offset = {x = (-10 * 24) - 25, y = -(48 + 24 + 16)},
}
local breath_bar_definition = {
hud_elem_type = "statbar",
- position = { x=0.5, y=1 },
+ position = {x = 0.5, y = 1},
text = "bubble.png",
number = core.PLAYER_MAX_BREATH_DEFAULT,
direction = 0,
- size = { x=24, y=24 },
- offset = {x=25,y=-(48+24+16)},
+ size = {x = 24, y = 24},
+ offset = {x = 25, y= -(48 + 24 + 16)},
}
local hud_ids = {}
@@ -26,7 +26,7 @@ local hud_ids = {}
local function scaleToDefault(player, field)
-- Scale "hp" or "breath" to the default dimensions
local current = player["get_" .. field](player)
- local nominal = core["PLAYER_MAX_".. field:upper() .. "_DEFAULT"]
+ local nominal = core["PLAYER_MAX_" .. field:upper() .. "_DEFAULT"]
local max_display = math.max(nominal,
math.max(player:get_properties()[field .. "_max"], current))
return current / max_display * nominal
@@ -49,6 +49,7 @@ local function update_builtin_statbars(player)
local hud = hud_ids[name]
local immortal = player:get_armor_groups().immortal == 1
+
if flags.healthbar and enable_damage and not immortal then
local number = scaleToDefault(player, "hp")
if hud.id_healthbar == nil then
@@ -63,19 +64,28 @@ local function update_builtin_statbars(player)
hud.id_healthbar = nil
end
+ local show_breathbar = flags.breathbar and enable_damage and not immortal
+
+ local breath = player:get_breath()
local breath_max = player:get_properties().breath_max
- if flags.breathbar and enable_damage and not immortal and
- player:get_breath() < breath_max then
+ if show_breathbar and breath <= breath_max then
local number = 2 * scaleToDefault(player, "breath")
- if hud.id_breathbar == nil then
+ if not hud.id_breathbar and breath < breath_max then
local hud_def = table.copy(breath_bar_definition)
hud_def.number = number
hud.id_breathbar = player:hud_add(hud_def)
- else
+ elseif hud.id_breathbar then
player:hud_change(hud.id_breathbar, "number", number)
end
- elseif hud.id_breathbar then
- player:hud_remove(hud.id_breathbar)
+ end
+
+ if hud.id_breathbar and (not show_breathbar or breath == breath_max) then
+ minetest.after(1, function(player_name, breath_bar)
+ local player = minetest.get_player_by_name(player_name)
+ if player then
+ player:hud_remove(breath_bar)
+ end
+ end, name, hud.id_breathbar)
hud.id_breathbar = nil
end
end