return game.assets.words[Math.floor(Math.random() * game.assets.words.length)];
}
+function playRandomSound(game) {
+ if(!game.view || !game.view.audioListener) {
+ return;
+ }
+ if(!game.view.lastSoundsCache) {
+ game.view.lastSoundsCache = [];
+ }
+ let index;
+ // We remember the last two notes played and make sure not to repeat one of those.
+ do {
+ index = 1 + Math.floor(Math.random() * 5);
+ } while(game.view.lastSoundsCache.includes(index));
+ game.view.lastSoundsCache.push(index);
+ if(game.view.lastSoundsCache.length > 2) {
+ game.view.lastSoundsCache.splice(0, 1);
+ }
+ let sound = new THREE.Audio(game.view.audioListener);
+ sound.setBuffer(game.assets['audio']['sound' + index]);
+ sound.setVolume(game.settings['audio']['sounds']);
+ sound.play();
+}
+
function easeInOut(val) {
return -0.5 * Math.cos(val * Math.PI) + 0.5;
}
return new Promise((resolve, reject) => {
let todoList = {
'audio/music.ogg': 1636930,
+ 'audio/sound1.ogg': 34002,
+ 'audio/sound2.ogg': 34629,
+ 'audio/sound3.ogg': 25399,
+ 'audio/sound4.ogg': 16426,
+ 'audio/sound5.ogg': 26122,
'fonts/cookie.json': 37866,
'textures/cloud0a.png': 568,
'textures/cloud0b.png': 569,
new THREE.Vector3().subVectors(word.position, game.objects.feather.position).length() < collectingRadius) {
word.collected = game.view.clock.getElapsedTime();
game.objects.words.collectedCount += 1;
+ playRandomSound(game);
}
if(word.parent != game.view.scene) {
// All that happens in here is the positional animation for the word, which
game.ui.root.querySelectorAll('button.goto').forEach((btn) => {
btn.addEventListener('click', (e) => {
if(!game.view.music) {
- const audioListener = new THREE.AudioListener();
- game.view.camera.add(audioListener);
- game.view.music = new THREE.Audio(audioListener);
+ game.view.audioListener = new THREE.AudioListener();
+ game.view.camera.add(game.view.audioListener);
+ game.view.music = new THREE.Audio(game.view.audioListener);
game.view.music.setBuffer(game.assets.audio.music);
game.view.music.setVolume(game.settings['audio']['music']);
}
game.view.music.stop();
}, 6000);
}
+ } else if(e.target.classList.contains('sounds')) {
+ playRandomSound(game);
}
});
});