added directional ambiance sounds

This commit is contained in:
kaadmy 2015-12-16 10:01:43 -08:00
parent 5bda98a03e
commit 8351ef7e0f
9 changed files with 156 additions and 59 deletions

10
mods/ambiance/README.txt Normal file
View File

@ -0,0 +1,10 @@
Ambiance mod
============
By Kaadmy, for Pixture
Adds directional ambient sounds coming from the correct sources.
Sound license:
ambiance_birds.ogg: CC0, by syncopika(http://opengameart.org/users/syncopika)
ambiance_crickets.ogg: CC0, by syncopika(http://opengameart.org/users/syncopika)
Source license: WTFPL

View File

@ -0,0 +1 @@
default

139
mods/ambiance/init.lua Normal file
View File

@ -0,0 +1,139 @@
--
-- Ambiance mod
-- By Kaadmy, for Pixture
--
ambiance = {}
ambiance.sounds = {}
ambiance.sounds["birds"] = {
length = 5.0,
chance = 4,
file = "ambiance_birds",
dist = 8,
nodename = "group:leaves",
can_play = function(pos)
local tod = (minetest.get_timeofday() or 1) * 2
if tod > 0.47 and tod < 1.53 then -- bit of overlap into crickets
return true
end
return false
end,
}
ambiance.sounds["crickets"] = {
length = 6.0,
chance = 3,
file = "ambiance_crickets",
dist = 8,
nodename = "group:grass",
can_play = function(pos)
local tod = (minetest.get_timeofday() or 1) * 2
if tod < 0.5 or tod > 1.5 then
return true
end
return false
end,
}
ambiance.sounds["flowing_water"] = {
length = 3.3,
chance = 1,
file = "default_water",
dist = 16,
nodename = "group:flowing_water",
}
local ambiance_volume = tonumber(minetest.setting_get("ambiance_volume")) or 1.0
local soundspec = {}
local lastsound = {}
local function ambient_node_near(sound, pos) local nodepos = minetest.find_node_near(pos, sound.dist, sound.nodename)
if nodepos ~= nil and math.random(1, sound.chance) == 1 then
return nodepos
end
return nil
end
local function step(dtime)
local player_positions = {}
for _, player in ipairs(minetest.get_connected_players()) do
local pos = player:getpos()
local name = player:get_player_name()
for soundname, sound in pairs(ambiance.sounds) do
if lastsound[name][soundname] then
lastsound[name][soundname] = lastsound[name][soundname] + dtime
else
lastsound[name][soundname] = 0
end
if lastsound[name][soundname] > sound.length then
local sourcepos = ambient_node_near(sound, pos)
if sound.can_play and sourcepos ~= nil and (not sound.can_play(sourcepos)) then
sourcepos = nil
end
if sourcepos == nil then
if soundspec[name][soundname] then
minetest.sound_stop(soundspec[name][soundname])
soundspec[name][soundname] = nil
lastsound[name][soundname] = 0
end
else
local ok = true
for _, p in pairs(player_positions) do
if (p.x * pos.x) + (p.y * pos.y) + (p.z * pos.z) < sound.dist*sound.dist then
ok = false
end
end
if ok then
soundspec[name][soundname] = minetest.sound_play(
sound.file,
{
pos = sourcepos,
max_hear_distance = sound.dist,
})
lastsound[name][soundname] = 0
end
end
end
end
table.insert(player_positions, pos)
end
end
local function on_joinplayer(player)
local name = player:get_player_name()
soundspec[name] = {}
lastsound[name] = {}
end
local function on_leaveplayer(player)
local name = player:get_player_name()
soundspec[name] = nil
lastsound[name] = nil
end
minetest.register_on_joinplayer(on_joinplayer)
minetest.register_on_leaveplayer(on_leaveplayer)
minetest.register_globalstep(step)
default.log("mod:ambiance", "loaded")

Binary file not shown.

View File

@ -1258,7 +1258,7 @@ minetest.register_node(
waving = 1,
walkable = false,
buildable_to = true,
groups = {snappy = 2, dig_immediate = 3, attached_node = 1},
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1},
sounds = default.node_sound_leaves_defaults(),
})
@ -1299,7 +1299,7 @@ minetest.register_node(
waving = 1,
walkable = false,
buildable_to = true,
groups = {snappy=2,dig_immediate=3,attached_node=1},
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1},
sounds = default.node_sound_leaves_defaults(),
})
@ -1320,7 +1320,7 @@ minetest.register_node(
waving = 1,
walkable = false,
buildable_to = true,
groups = {snappy=2,dig_immediate=3,attached_node=1},
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1},
sounds = default.node_sound_leaves_defaults(),
})
@ -1341,7 +1341,7 @@ minetest.register_node(
waving = 1,
walkable = false,
buildable_to = true,
groups = {snappy=2,dig_immediate=3,attached_node=1},
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1},
sounds = default.node_sound_leaves_defaults(),
})
@ -1363,7 +1363,7 @@ minetest.register_node(
waving = 1,
walkable = false,
buildable_to = true,
groups = {snappy=2,dig_immediate=3,attached_node=1},
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1},
sounds = default.node_sound_leaves_defaults(),
})

View File

@ -5,9 +5,6 @@ local player_lastpos = {}
local particlespawners = {}
local enable_flowing_water_sound = minetest.setting_getbool("enable_flowing_water_sound")
if enable_flowing_water_sound == nil then enable_flowing_water_sound = true end
local function step(dtime)
local player_positions = {}
@ -44,11 +41,6 @@ local function step(dtime)
player_lastsound[name] = player_lastsound[name] + dtime
local flowing_water_pos = nil
if enable_flowing_water_sound then
flowing_water_pos = minetest.find_node_near(player_pos, 16, "group:flowing_water")
end
if nodename == "default:water_source" or nodename == "default:river_water_source" then
if player_lastsound[name] > 3.3 then
player_soundspec[name]=minetest.sound_play(
@ -78,27 +70,6 @@ local function step(dtime)
})
minetest.after(0.15, function() minetest.delete_particlespawner(particlespawners[name]) end)
elseif flowing_water_pos then
if player_lastsound[name] > 3.3 then
local c = true
for _, p in pairs(player_positions) do
if (p.x * player_pos.x) + (p.y * player_pos.y) + (p.z * player_pos.z) < 256 then
-- 256 is 16*16 for distance checking
c = false
end
end
if c then
player_soundspec[name]=minetest.sound_play(
"default_water",
{
pos = flowing_water_pos,
max_hear_distance = 16,
})
player_lastsound[name] = 0
end
end
else
if player_soundspec[name] ~= nil then
minetest.sound_stop(player_soundspec[name])

View File

@ -4,7 +4,6 @@ By Kaadmy, for Pixture
Texture license: WTFPL
Sound license:
weather_night.ogg: CC0
weather_storm.ogg: GPLv2(Replace this, I want CC0/WTFPL-only assets)
weather_snowstorm.ogg: GPLv2(Replace this, I want CC0/WTFPL-only assets)
Source license: WTFPL

View File

@ -21,30 +21,7 @@ local function play_sound()
minetest.sound_stop(weather_soundspec)
end
local timeofday=minetest.get_timeofday()
if timeofday == nil then
timeofday=1
end
timeofday=timeofday*2
if weather.weather == "clear" then
if (timeofday > 0.4 and timeofday < 0.5) or (timeofday > 1.5 and timeofday < 1.6) then
-- dusk and dawn
weather_soundspec=minetest.sound_play({name="weather_night", gain=0.5})
minetest.after(12, play_sound)
return
elseif (timeofday < 0.4 or timeofday > 1.6) then
-- night
weather_soundspec=minetest.sound_play({name="weather_night", gain=0.3})
minetest.after(12, play_sound)
return
end
-- daytime
elseif weather.weather == "storm" then
if weather.weather == "storm" then
weather_soundspec=minetest.sound_play({name="weather_storm"})
minetest.after(18, play_sound)