From 95899878c79b638a37e1e6c244051f72488fc05a Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Tue, 22 Aug 2023 16:04:52 -0500 Subject: [PATCH] randomized sounds better, made config easier for adding new effects. --- src/util/customEnvironment.ts | 12 ++++++------ src/util/diaSounds.ts | 22 +++++++++------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/util/customEnvironment.ts b/src/util/customEnvironment.ts index 16e1407..59c1f76 100644 --- a/src/util/customEnvironment.ts +++ b/src/util/customEnvironment.ts @@ -39,25 +39,25 @@ export class CustomEnvironment { window.setTimeout((sound) => { sound.play() }, 2000, sounds.background); - const birds: Array = [sounds.birds, sounds.dove]; + const effects: Array = sounds.backgroundEffects; window.setInterval((sounds: Array) => { - if (Math.random() < .6) { + if (Math.random() < .5) { return; } const sound = Math.floor(Math.random() * sounds.length); - const x = Math.floor(Math.random() * 20); - const z = Math.floor(Math.random() * 20); + const x = Math.floor(Math.random() * 20) - 10; + const z = Math.floor(Math.random() * 20) - 10; const position = new Vector3(x, 0, z); if (sounds[sound].isPlaying) { } else { sounds[sound].setPosition(position); - sounds[sound].setVolume(Math.random() * .5); + sounds[sound].setVolume(Math.random() * .3); sounds[sound].play(); } - }, 2000, birds); + }, 2000, effects); } catch (error) { console.log(error); } diff --git a/src/util/diaSounds.ts b/src/util/diaSounds.ts index a1ee6b3..e79de66 100644 --- a/src/util/diaSounds.ts +++ b/src/util/diaSounds.ts @@ -3,8 +3,6 @@ import {Scene, Sound} from "@babylonjs/core"; export class DiaSounds { private readonly scene: Scene; - private readonly _birds: Sound; - public get tick() { return new Sound("tick", '/assets/sounds/tick.mp3', this.scene); } @@ -53,8 +51,15 @@ export class DiaSounds { volume: .5, loop: false } - this._birds = this.buildSpatialSound("warbler", "/assets/sounds/warbler.mp3"); - this._dove = this.buildSpatialSound("dove", "/assets/sounds/dove.mp3"); + this._backgroundEffects.push(this.buildSpatialSound("warbler2", "/assets/sounds/warbler2.mp3")); + this._backgroundEffects.push(this.buildSpatialSound("warbler3", "/assets/sounds/warbler3.mp3")); + this._backgroundEffects.push(this.buildSpatialSound("crickets", "/assets/sounds/crickets.mp3")); + this._backgroundEffects.push(this.buildSpatialSound("dove", "/assets/sounds/dove.mp3")) + } + + _backgroundEffects: Array = []; + public get backgroundEffects(): Array { + return this._backgroundEffects; } private buildSpatialSound(name: string, url: string) { @@ -92,15 +97,6 @@ export class DiaSounds { return this._low; } - public get birds(): Sound { - return this._birds; - } - - _dove: Sound; - public get dove() { - return this._dove; - } - public get bounce() { const bounce = this._bounce.clone(); bounce.updateOptions({offset: 0, volume: this.volume, length: .990});