Skip to content

Commit

Permalink
Ambient music.
Browse files Browse the repository at this point in the history
  • Loading branch information
tapio committed Nov 30, 2012
1 parent b1a0daa commit e8539e6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
Binary file added assets/music/dark-ambiance-01.ogg
Binary file not shown.
5 changes: 5 additions & 0 deletions assets/music/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dark-ambiance-01.ogg
By Philippe Groarke (Socapex)
http://opengameart.org/content/dark-ambiance
CC-BY-SA-3.0

1 change: 1 addition & 0 deletions js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var CONFIG = {
resolution: 1.0,
physicsFPS: 60,
sounds: true,
music: true,
postprocessing: true,
particles: true,
maxLights: 4,
Expand Down
2 changes: 2 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ function resetLevel(levelName) {
soundManager = new SoundManager();
aiManager = new AIManager();
dungeon = new Dungeon(scene, pl, levelName);

if (CONFIG.music) soundManager.playMusic("dark-ambiance-01");
}

function savePlayerState(levelName) {
Expand Down
12 changes: 12 additions & 0 deletions js/sound.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

function SoundManager() {
var sounds = {};
var music;
for (var s in assets.sounds)
sounds[s] = new Sound(assets.sounds[s], 5);

Expand All @@ -14,6 +15,17 @@ function SoundManager() {
if (distance < radius)
sounds[name].play(1 - distance / radius);
};

this.playMusic = function(name) {
this.stopMusic();
music = new Audio("assets/music/" + name + ".ogg");
music.loop = true;
music.play();
};

this.stopMusic = function() {
if (music) music.pause();
};
}

function Sound(samples, minPlayers) {
Expand Down
8 changes: 7 additions & 1 deletion js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ function initUI() {
gui.add(CONFIG, "resolution", 0.1, 1.0).step(0.1).onChange(function() { updateConfig(); onWindowResize(); });
gui.add(CONFIG, "physicsFPS", 30, 100).step(10).onChange(updateConfig);
gui.add(CONFIG, "showStats").onChange(updateConfig);
gui.add(CONFIG, "sounds").onChange(updateConfig);
gui.add(controls, "mouseFallback");
gui.add(window, "editLevel");
var guiAudio = gui.addFolder("Audio");
guiAudio.add(CONFIG, "sounds").onChange(updateConfig);
guiAudio.add(CONFIG, "music").onChange(function() {
if (CONFIG.music) soundManager.playMusic("dark-ambiance-01");
else soundManager.stopMusic();
updateConfig();
});
var guiRenderer = gui.addFolder("Renderer options (reload required)");
guiRenderer.add(CONFIG, "antialias").onChange(updateConfig);
guiRenderer.add(CONFIG, "physicalShading").onChange(updateConfig);
Expand Down

0 comments on commit e8539e6

Please sign in to comment.