Improve hudbars

This commit is contained in:
IamPyu 2024-12-07 15:07:20 -06:00
parent 213dcbe06c
commit f3acc9a3dc
6 changed files with 86 additions and 15 deletions

View File

@ -13,6 +13,7 @@ Notable Game Changes:
- Add back the Rubies that were removed a while ago!
- Replaced Spawnpoints with a item
- Added Pigs
- Improved hudbars
Other Game Changes:

View File

@ -51,3 +51,19 @@ PyuTest.make_mob("pyutest_entities:item_follower", {
"pyutest_tools:coin"
}
})
PyuTest.make_mob("pyutest_entities:pig", {
hp_max = 10,
visual = "mesh",
mesh = "pyutest-pig.glb",
visual_size = {x = 6, y = 8, z = 8},
textures = {"pyutest-pig.png"},
nametag = "Pig",
collisionbox = PyuTest.BLOCK_SIZED_ANIMAL_CBOX,
selectionbox = PyuTest.NODEBOX_DEFAULT.fixed,
}, {
drops = {},
follow_items = {
"pyutest_tools:carrot"
}
})

View File

@ -153,9 +153,8 @@ mobs:register_mob("pyutest_mobs:pig", {
fear_height = 5,
blood_amount = PyuTest.ENTITY_BLOOD_AMOUNT,
makes_footstep_sound = true,
visual_size = {x = 6, y = 8, z = 8},
collisionbox = PyuTest.BLOCK_SIZED_ANIMAL_CBOX,
selectionbox = PyuTest.NODEBOX_DEFAULT.fixed,
visual_size = {x = 9, y = 9, z = 9},
collisionbox = {-0.45, -0.01, -0.45, 0.45, 0.865, 0.45},
can_leap = false,
jump = false,
pushable = false

View File

@ -141,6 +141,7 @@ PyuTest.make_node("pyutest_blocks:workbench", "Workbench", {
PyuTest.make_node("pyutest_blocks:ladder", "Ladder", {
dig_immediate = 1,
oddly_breakable_by_hand = PyuTest.BLOCK_FAST,
choppy = PyuTest.BLOCK_FAST,
block = 1
}, { "pyutest-ladder.png" }, {
drawtype = "signlike",

View File

@ -1,15 +1,69 @@
core.hud_replace_builtin("health", {})
core.hud_replace_builtin("breath", {})
PyuTest.HUDBARS = {
defs = {},
defs_count = 0,
players = {}
}
PyuTest.Hudbar = {}
local HudbarMeta = { __index = PyuTest.Hudbar, __newindex = PyuTest.Hudbar }
core.hud_replace_builtin("health", {
hud_elem_type = "statbar",
text = "pyutest-bar-health.png",
text2 = "pyutest-bar-empty.png",
number = core.PLAYER_MAX_HP_DEFAULT,
item = core.PLAYER_MAX_HP_DEFAULT,
position = {x = 0.5, y = 1},
direction = 0,
size = {x = 24, y = 24},
offset = {x = (-10 * 24) - 25, y = -(48 + 24 + 16)},
})
core.register_on_joinplayer(function(player)
for k, v in pairs(PyuTest.HUDBARS.defs) do
local key = player:get_player_name()
if PyuTest.HUDBARS.players[key] == nil then
PyuTest.HUDBARS.players[key] = {}
end
local ref = PyuTest.HUDBARS.players[key]
ref[k] = {idx = player:hud_add(v.cfg), name = k}
end
end)
core.register_globalstep(function(dtime)
for _, player in pairs(core.get_connected_players()) do
for _, v in pairs(PyuTest.HUDBARS.players[player:get_player_name()]) do
PyuTest.HUDBARS.defs[v.name].update(v.idx, player)
end
end
end)
function PyuTest.Hudbar:add(name, def, update)
local cfg = def or {}
cfg.hud_elem_type = "statbar"
cfg.position = {x = 0.5, y = 0.925}
cfg.direction = 0
cfg.size = {x = 24, y = 24}
cfg.offset = {x = (-10 * 24 - 25) * -(PyuTest.HUDBARS.defs_count - 1), y = (-48 + 24 + 16)}
cfg.text2 = cfg.text2 or "pyutest-bar-empty.png"
local m = setmetatable({
cfg = cfg,
update = update or function()end
}, HudbarMeta)
PyuTest.HUDBARS.defs[name] = m
PyuTest.HUDBARS.defs_count = PyuTest.HUDBARS.defs_count + 1
end
local enable_damage = core.settings:get_bool("enable_damage")
if enable_damage then
PyuTest.Hudbar:add("health", {
text = "pyutest-bar-health.png",
number = core.PLAYER_MAX_HP_DEFAULT,
item = core.PLAYER_MAX_HP_DEFAULT,
}, function (idx, player)
player:hud_change(idx, "number", player:get_hp())
end)
PyuTest.Hudbar:add("breath", {
text = "pyutest-bar-breath.png",
number = core.PLAYER_MAX_BREATH_DEFAULT,
item = core.PLAYER_MAX_BREATH_DEFAULT,
}, function (idx, player)
player:hud_change(idx, "number", player:get_breath())
end)
end

View File