Skip to content

Commit

Permalink
Use a random pitch and gain for the sound
Browse files Browse the repository at this point in the history
The volume is lower now in general.
  • Loading branch information
HybridDog committed Sep 16, 2021
1 parent edb33a4 commit 15545f9
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ else
end
end

local function tree_fall_sound(pos)
if treecapitator.play_sound then
minetest.sound_play("tree_falling", {
gain = 0.2 + 0.2 * math.random() ^ 2,
pitch = 0.7 + 0.5 * math.random(),
pos = pos,
max_hear_distance = 32
}, true)
end
end


local function table_contains(t, v)
for i = 1,#t do
Expand Down Expand Up @@ -486,9 +497,7 @@ function capitate_funcs.default(pos, tr, _, digger)
end

-- tree was capitated, play sound
if treecapitator.play_sound then
minetest.sound_play("tree_falling", {pos = pos, max_hear_distance = 32})
end
tree_fall_sound(pos)
return true
end

Expand Down Expand Up @@ -602,9 +611,7 @@ function capitate_funcs.acacia(pos, tr, node_above, digger)
end

-- play the sound, then dig the stem
if treecapitator.play_sound then
minetest.sound_play("tree_falling", {pos = pos, max_hear_distance = 32})
end
tree_fall_sound(pos)
for i = 1,n-1 do
local pos_stem, node = unpack(tab[i])
destroy_node(pos_stem, node, digger)
Expand Down Expand Up @@ -813,10 +820,7 @@ function capitate_funcs.palm(startpos, tr, node_above, digger)
local leaves_ps = {}
local lc = palm_find_valid_head_ps(hcp, leaves_ps, tr)

if treecapitator.play_sound then
minetest.sound_play("tree_falling", {pos = pos_current,
max_hear_distance = 32})
end
tree_fall_sound(pos_current)

local nodeupdate = minetest.check_for_falling
minetest.check_for_falling = function() end
Expand Down Expand Up @@ -928,9 +932,7 @@ function capitate_funcs.moretrees(pos, tr, _, digger)
print("wrong leaves num: "..num_leaves)
return
end
if treecapitator.play_sound then
minetest.sound_play("tree_falling", {pos = pos, max_hear_distance = 32})
end
tree_fall_sound(pos)
local inv = digger:get_inventory()
for _,p in pairs(ps) do
local node = get_node(p)
Expand Down

0 comments on commit 15545f9

Please sign in to comment.