Add particle effects for chest unlock

master
Wuzzy 2022-03-04 15:51:46 +01:00
parent 9b1768b51a
commit 22855b4e3e
5 changed files with 74 additions and 4 deletions

View File

@ -103,12 +103,17 @@ end
function lzr_laser.unlock_chests(min, max)
local closed_chests = minetest.find_nodes_in_area(min, max, {"group:chest_closed"})
local detectors = minetest.find_nodes_in_area(min, max, {"group:detector"})
for c=1, #closed_chests do
local pos = closed_chests[c]
local node = minetest.get_node(pos)
local cpos = closed_chests[c]
local node = minetest.get_node(cpos)
local def = minetest.registered_nodes[node.name]
if def._lzr_unlock then
def._lzr_unlock(pos, node)
def._lzr_unlock(cpos, node)
for d=1, #detectors do
local dpos = detectors[d]
lzr_laser.particle_line(dpos, cpos, "lzr_laser_particle_trigger.png")
end
end
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -98,3 +98,31 @@ function lzr_laser.bitwise_or(bin1, bin2)
end
return out
end
-- Generates a line of particles between `pos1` and `pos2` with particle texture `particle`
function lzr_laser.particle_line(pos1, pos2, particle)
local steps = 30
local amount = 10
local spread = 0.1
local vspread = 0.01
local size = 0.4
local pos = vector.copy(pos1)
for i=0,steps-1 do
pos.x = pos1.x + (pos2.x - pos1.x) * (i/steps)
pos.y = pos1.y + (pos2.y - pos1.y) * (i/steps)
pos.z = pos1.z + (pos2.z - pos1.z) * (i/steps)
minetest.add_particlespawner({
amount = amount,
time = 0.001,
minpos = vector.subtract(pos, vector.new(spread, spread, spread)),
maxpos = vector.add(pos, vector.new(spread, spread, spread)),
minvel = vector.new(-vspread, -vspread, -vspread),
maxvel = vector.new(vspread, vspread, vspread),
minsize = size,
maxsize = size,
texture = particle,
minexptime = 1.5,
maxexptime = 1.7,
})
end
end

View File

@ -51,8 +51,45 @@ local register_chest = function(id, def)
end,
-- Unlock chest
_lzr_unlock = function(pos, node)
minetest.sound_play({name=sound_lock_break, gain=0.8}, {pos=pos}, true)
minetest.set_node(pos, {name="lzr_treasure:chest_"..id.."_unlocked", param2=node.param2})
minetest.sound_play({name=sound_lock_break, gain=0.8}, {pos=pos}, true)
local dir = minetest.facedir_to_dir(node.param2)
local w = 3/16
local k = 9/16
local l = 8/16
local minoff, maxoff
if dir.x > 0 then
minoff = vector.new(-k, -w, -w)
maxoff = vector.new(-l, w, w)
elseif dir.x < 0 then
minoff = vector.new(l, -w, -w)
maxoff = vector.new(k, w, w)
elseif dir.z > 0 then
minoff = vector.new(-w, -w, -k)
maxoff = vector.new(w, w, -l)
elseif dir.z < 0 then
minoff = vector.new(-w, -w, l)
maxoff = vector.new(w, w, k)
end
if minoff then
minetest.add_particlespawner({
amount = 12,
time = 0.001,
minpos = vector.add(pos, minoff),
maxpos = vector.add(pos, maxoff),
minvel = vector.new(-0.5, -0.2, -0.5),
maxvel = vector.new(0.5, 0.5, 0.5),
minacc = vector.new(0, -lzr_globals.GRAVITY, 0),
maxacc = vector.new(0, -lzr_globals.GRAVITY, 0),
minsize = 0.5,
maxsize = 0.5,
minexptime = 0.60,
maxexptime = 0.65,
texture = "lzr_treasure_particle_lock.png",
})
end
end,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB