Added splash and improved get_ambience() a bit
parent
d626a26758
commit
e17ca3c8b3
70
init.lua
70
init.lua
|
@ -63,6 +63,12 @@ local water_frequent = {
|
||||||
{name="scuba1tubulentbubbles", length=10.5},
|
{name="scuba1tubulentbubbles", length=10.5},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local splash = {
|
||||||
|
handler = {},
|
||||||
|
frequency = 100,
|
||||||
|
{name="Splash", length=1.5},
|
||||||
|
}
|
||||||
|
|
||||||
local play_music = minetest.setting_getbool("music") or false
|
local play_music = minetest.setting_getbool("music") or false
|
||||||
local music = {
|
local music = {
|
||||||
handler = {},
|
handler = {},
|
||||||
|
@ -81,36 +87,56 @@ local is_daytime = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
local get_ambience = function(player)
|
local get_ambience = function(player)
|
||||||
|
local table = {}
|
||||||
|
|
||||||
|
local play_water = false
|
||||||
|
local play_splash = false
|
||||||
|
local play_day = false
|
||||||
|
local play_cave = false
|
||||||
|
local play_night = false
|
||||||
|
|
||||||
local pos = player:getpos()
|
local pos = player:getpos()
|
||||||
pos.y = pos.y+1.5
|
pos.y = pos.y+1.5
|
||||||
local nodename = minetest.env:get_node(pos).name
|
local nodename = minetest.env:get_node(pos).name
|
||||||
if string.find(nodename, "default:water") then
|
if string.find(nodename, "default:water") then
|
||||||
if music then
|
play_water = true
|
||||||
return {water=water, water_frequent=water_frequent, music=music}
|
elseif nodename == "air" then
|
||||||
else
|
pos.y = pos.y-1.5
|
||||||
return {water=water, water_frequent=water_frequent}
|
local nodename = minetest.env:get_node(pos).name
|
||||||
|
if string.find(nodename, "default:water") then
|
||||||
|
play_splash = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if player:getpos().y < 0 then
|
if player:getpos().y < 0 then
|
||||||
if music then
|
play_cave = true
|
||||||
return {cave=cave, cave_frequent=cave_frequent, music=music}
|
elseif is_daytime() then
|
||||||
|
play_day = true
|
||||||
else
|
else
|
||||||
return {cave=cave, cave_frequent=cave_frequent}
|
play_night = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if play_music then
|
||||||
|
table.music = music
|
||||||
end
|
end
|
||||||
if is_daytime() then
|
if play_water then
|
||||||
if music then
|
table.water = water
|
||||||
return {day=day, day_frequent=day_frequent, music=music}
|
table.water_frequent = water_frequent
|
||||||
else
|
return table
|
||||||
return {day=day, day_frequent=day_frequent}
|
|
||||||
end
|
end
|
||||||
else
|
if play_splash then
|
||||||
if music then
|
table.splash = splash
|
||||||
return {night=night, night_frequent=night_frequent, music=music}
|
|
||||||
else
|
|
||||||
return {night=night, night_frequent=night_frequent}
|
|
||||||
end
|
end
|
||||||
|
if play_day then
|
||||||
|
table.day = day
|
||||||
|
table.day_frequent = day_frequent
|
||||||
|
elseif play_night then
|
||||||
|
table.night = night
|
||||||
|
table.night_frequent = night_frequent
|
||||||
|
elseif play_cave then
|
||||||
|
table.cave = cave
|
||||||
|
table.cave_frequent = cave_frequent
|
||||||
end
|
end
|
||||||
|
return table
|
||||||
end
|
end
|
||||||
|
|
||||||
-- start playing the sound, set the handler and delete the handler after sound is played
|
-- start playing the sound, set the handler and delete the handler after sound is played
|
||||||
|
@ -229,6 +255,16 @@ local stop_sound = function(still_playing, player)
|
||||||
list.handler[player_name] = nil
|
list.handler[player_name] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if still_playing.splash == nil then
|
||||||
|
local list = splash
|
||||||
|
if list.handler[player_name] ~= nil then
|
||||||
|
if list.on_stop ~= nil then
|
||||||
|
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||||
|
end
|
||||||
|
minetest.sound_stop(list.handler[player_name])
|
||||||
|
list.handler[player_name] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local timer = 0
|
local timer = 0
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue