Skip to content

Commit

Permalink
Fix 10.5 bubbles being displayed for high breath_max values
Browse files Browse the repository at this point in the history
This was because of PLAYER_MAX_BREATH_DEFAULT being set to 11 instead of 10, probably so that all 10 bubbles are shown before the breath bar disappears.

Now, since PLAYER_MAX_BREATH_DEFAULT is 10, only a maximum of 9.5 bubbles would be visible before the breath bar disappears.
  • Loading branch information
ClobberXD committed Feb 27, 2019
1 parent 111f1dc commit a803d10
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion builtin/game/constants.lua
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions builtin/game/statbars.lua
Expand Up @@ -29,9 +29,13 @@ 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"]
if field == "breath" then
-- Show up/scale to 10 bubbles. Default 11 lets the bar disappear.
nominal = nominal - 1
end
local max_display = math.max(nominal,
math.max(player:get_properties()[field .. "_max"], current))
return current / max_display * nominal
math.max(player:get_properties()[field .. "_max"], current))
return current / max_display * nominal
end

local function update_builtin_statbars(player)
Expand All @@ -52,8 +56,8 @@ local function update_builtin_statbars(player)

if flags.healthbar and enable_damage then
local number = scaleToDefault(player, "hp")
if hud.id_healthbar == nil then
local hud_def = table.copy(health_bar_definition)
if hud.id_healthbar == nil then
local hud_def = table.copy(health_bar_definition)
hud_def.number = number
hud.id_healthbar = player:hud_add(hud_def)
else
Expand All @@ -69,7 +73,7 @@ local function update_builtin_statbars(player)
player:get_breath() < breath_max then
local number = 2 * scaleToDefault(player, "breath")
if hud.id_breathbar == nil then
local hud_def = table.copy(breath_bar_definition)
local hud_def = table.copy(breath_bar_definition)
hud_def.number = number
hud.id_breathbar = player:hud_add(hud_def)
else
Expand Down
2 changes: 1 addition & 1 deletion src/constants.h
Expand Up @@ -93,7 +93,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define PLAYER_MAX_HP_DEFAULT 20

// Default maximal breath of a player
#define PLAYER_MAX_BREATH_DEFAULT 11
#define PLAYER_MAX_BREATH_DEFAULT 10

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

0 comments on commit a803d10

Please sign in to comment.