Skip to content

Commit a36c9c3

Browse files
authoredApr 28, 2020
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
1 parent a368e7e commit a36c9c3

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed
 

Diff for: ‎builtin/game/constants.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ core.MAP_BLOCKSIZE = 16
2424
-- Default maximal HP of a player
2525
core.PLAYER_MAX_HP_DEFAULT = 20
2626
-- Default maximal breath of a player
27-
core.PLAYER_MAX_BREATH_DEFAULT = 11
27+
core.PLAYER_MAX_BREATH_DEFAULT = 10
2828

2929
-- light.h
3030
-- Maximum value for node 'light_source' parameter

Diff for: ‎builtin/game/statbars.lua

+23-13
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ local enable_damage = core.settings:get_bool("enable_damage")
33

44
local health_bar_definition = {
55
hud_elem_type = "statbar",
6-
position = { x=0.5, y=1 },
6+
position = {x = 0.5, y = 1},
77
text = "heart.png",
88
number = core.PLAYER_MAX_HP_DEFAULT,
99
direction = 0,
10-
size = { x=24, y=24 },
11-
offset = { x=(-10*24)-25, y=-(48+24+16)},
10+
size = {x = 24, y = 24},
11+
offset = {x = (-10 * 24) - 25, y = -(48 + 24 + 16)},
1212
}
1313

1414
local breath_bar_definition = {
1515
hud_elem_type = "statbar",
16-
position = { x=0.5, y=1 },
16+
position = {x = 0.5, y = 1},
1717
text = "bubble.png",
1818
number = core.PLAYER_MAX_BREATH_DEFAULT,
1919
direction = 0,
20-
size = { x=24, y=24 },
21-
offset = {x=25,y=-(48+24+16)},
20+
size = {x = 24, y = 24},
21+
offset = {x = 25, y= -(48 + 24 + 16)},
2222
}
2323

2424
local hud_ids = {}
2525

2626
local function scaleToDefault(player, field)
2727
-- Scale "hp" or "breath" to the default dimensions
2828
local current = player["get_" .. field](player)
29-
local nominal = core["PLAYER_MAX_".. field:upper() .. "_DEFAULT"]
29+
local nominal = core["PLAYER_MAX_" .. field:upper() .. "_DEFAULT"]
3030
local max_display = math.max(nominal,
3131
math.max(player:get_properties()[field .. "_max"], current))
3232
return current / max_display * nominal
@@ -49,6 +49,7 @@ local function update_builtin_statbars(player)
4949
local hud = hud_ids[name]
5050

5151
local immortal = player:get_armor_groups().immortal == 1
52+
5253
if flags.healthbar and enable_damage and not immortal then
5354
local number = scaleToDefault(player, "hp")
5455
if hud.id_healthbar == nil then
@@ -63,19 +64,28 @@ local function update_builtin_statbars(player)
6364
hud.id_healthbar = nil
6465
end
6566

67+
local show_breathbar = flags.breathbar and enable_damage and not immortal
68+
69+
local breath = player:get_breath()
6670
local breath_max = player:get_properties().breath_max
67-
if flags.breathbar and enable_damage and not immortal and
68-
player:get_breath() < breath_max then
71+
if show_breathbar and breath <= breath_max then
6972
local number = 2 * scaleToDefault(player, "breath")
70-
if hud.id_breathbar == nil then
73+
if not hud.id_breathbar and breath < breath_max then
7174
local hud_def = table.copy(breath_bar_definition)
7275
hud_def.number = number
7376
hud.id_breathbar = player:hud_add(hud_def)
74-
else
77+
elseif hud.id_breathbar then
7578
player:hud_change(hud.id_breathbar, "number", number)
7679
end
77-
elseif hud.id_breathbar then
78-
player:hud_remove(hud.id_breathbar)
80+
end
81+
82+
if hud.id_breathbar and (not show_breathbar or breath == breath_max) then
83+
minetest.after(1, function(player_name, breath_bar)
84+
local player = minetest.get_player_by_name(player_name)
85+
if player then
86+
player:hud_remove(breath_bar)
87+
end
88+
end, name, hud.id_breathbar)
7989
hud.id_breathbar = nil
8090
end
8191
end

Diff for: ‎src/constants.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
9393
#define PLAYER_MAX_HP_DEFAULT 20
9494

9595
// Default maximal breath of a player
96-
#define PLAYER_MAX_BREATH_DEFAULT 11
96+
#define PLAYER_MAX_BREATH_DEFAULT 10
9797

9898
// Number of different files to try to save a player to if the first fails
9999
// (because of a case-insensitive filesystem)

0 commit comments

Comments
 (0)
Please sign in to comment.