Skip to content
Snippets Groups Projects
Commit 96010df5 authored by dg's avatar dg
Browse files

Added ambient sounds to the trollmire and the old forest

git-svn-id: http://svn.net-core.org/repos/t-engine4@4560 51575b47-30f0-44d4-a5cc-537603b46e54
parent b3756b5a
No related branches found
No related tags found
No related merge requests found
Showing
with 36 additions and 2 deletions
......@@ -45,12 +45,12 @@ function _M:playSound(name)
def = f()
print("[SOUND] loading from", "/data/sound/"..name..".lua", ":=:", "/data/sound/"..def.file, ":>")
ok, def.sample = pcall(core.sound.load, "/data/sound/"..def.file, false)
if not ok then return end
if not ok then print("Failed loading sound", def.file, def.sample) return end
print("[SOUND] :=>", def.sample)
elseif fs.exists("/data/sound/"..name..".ogg") then
def = {}
ok, def.sample = pcall(core.sound.load, "/data/sound/"..name..".ogg", false)
if not ok then return end
if not ok then print("Failed loading sound", name, def.sample) return end
print("[SOUND] loading from", "/data/sound/"..name..".ogg", ":=:", def.sample)
else
def = {}
......
......@@ -960,6 +960,9 @@ function _M:display(nb_keyframes)
if config.settings.tome.smooth_fov then map._map:drawSeensTexture(map.display_x, map.display_y, nb_keyframes) end
end
-- Handle ambient sounds
if self.level.data.ambient_bg_sounds then self.state:playAmbientSounds(self.level, self.level.data.ambient_bg_sounds, nb_keyframes) end
if not self.zone_name_s then self:updateZoneName() end
self.zone_name_s:toScreenFull(
map.display_x + map.viewport.width - self.zone_name_w - 15,
......
......@@ -510,6 +510,37 @@ function _M:handleWorldEncounter(target)
end
end
--------------------------------------------------------------------
-- Ambient sounds stuff
--------------------------------------------------------------------
function _M:makeAmbientSounds(level, t)
local s = {}
level.data.ambient_bg_sounds = s
for chan, data in pairs(t) do
data.name = chan
s[#s+1] = data
end
end
function _M:playAmbientSounds(level, s, nb_keyframes)
for i = 1, #s do
local data = s[i]
if data._sound then if not data._sound:playing() then data._sound = nil end end
if not data._sound and nb_keyframes > 0 and rng.chance(math.ceil(data.chance / nb_keyframes)) then
local f = rng.table(data.files)
data._sound = game:playSound(f)
print("===playing", data.name, f, data._sound)
if data._sound then
if data.volume_mod then data._sound:volume(data._sound:volume() * data.volume_mod) end
if data.pitch then data._sound:pitch(data.pitch) end
end
end
end
end
--------------------------------------------------------------------
-- Weather stuff
--------------------------------------------------------------------
......
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment