Add chest win effect to lzr_levels

master
Wuzzy 2022-03-04 01:34:39 +01:00
parent 6c026275b9
commit 8f8167bd8f
2 changed files with 26 additions and 4 deletions

View File

@ -287,6 +287,18 @@ function lzr_levels.level_complete()
return false
end
lzr_levels.mark_level_as_complete(current_level)
-- Trigger chest treasure particle animation
local open_chests = minetest.find_nodes_in_area(lzr_globals.PLAYFIELD_START, lzr_globals.PLAYFIELD_END, {"group:chest_open"})
for c=1, #open_chests do
local pos = open_chests[c]
local node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]
if def._lzr_send_treasure then
def._lzr_send_treasure(pos, node)
end
end
local player = get_singleplayer()
lzr_messages.show_message(player, S("@1 complete!", lzr_levels.get_level_name(current_level)), 3)
minetest.log("action", "[lzr_levels] Level "..current_level.." completed")

View File

@ -25,13 +25,14 @@ local register_chest = function(id, def)
sounds = def.node_sounds,
on_rotate = screwdriver.rotate_simple,
on_punch = function(pos, node, puncher)
if lzr_gamestate.get_state() ~= lzr_gamestate.LEVEL then
return
end
minetest.log("action", "[lzr_treasure] "..puncher:get_player_name().." opens "..node.name.." at "..minetest.pos_to_string(pos))
minetest.set_node(pos, {name="lzr_treasure:chest_"..id.."_open_"..treasure_id, param2=node.param2})
minetest.sound_play({name=sound_open, gain=0.5}, {pos=pos}, true)
local done = lzr_laser.check_level_won()
if done then
lzr_levels.level_complete()
end
local timer = minetest.get_node_timer(pos)
timer:start(1)
end,
})
@ -43,6 +44,9 @@ local register_chest = function(id, def)
sounds = def.node_sounds,
on_rotate = screwdriver.rotate_simple,
on_punch = function(pos, node, puncher)
if lzr_gamestate.get_state() ~= lzr_gamestate.LEVEL then
return
end
minetest.sound_play({name=sound_open_fail, gain=0.3}, {pos=pos}, true)
end,
-- Unlock chest
@ -112,6 +116,12 @@ local register_chest = function(id, def)
"("..def.tile_side..")^("..treasure_tile_side.."^[mask:lzr_treasure_mask_block_in_chest_side.png)",
"("..def.tile_front..")^("..treasure_tile_side.."^[mask:lzr_treasure_mask_block_in_chest_side.png)",
},
on_timer = function(pos)
local done = lzr_laser.check_level_won()
if done then
lzr_levels.level_complete()
end
end,
-- Removes the treasure from the chest and spawns particles (for level finish)
_lzr_send_treasure = function(pos, node)
for i=0,30 do