diff --git a/scripts/population.js b/scripts/population.js index 4ecd76e..5df73d2 100644 --- a/scripts/population.js +++ b/scripts/population.js @@ -120,9 +120,10 @@ function popDeaths(){ homelessDeathChance = Math.round(homelessDeathChance); - let popDeath = rand(0,100) < homelessDeathChance; + const popDeathChance = rand(0, 100) < homelessDeathChance; + let popDeath = 0; - if(popDeath){ + if(popDeathChance){ popDeath = Math.ceil((rand(0,homelessDeathChance)/100)*homelessPops); } diff --git a/scripts/sound.js b/scripts/sound.js index a8cea71..75188ea 100644 --- a/scripts/sound.js +++ b/scripts/sound.js @@ -1,6 +1,6 @@ import { rand } from "./funcs.js" -var audio = new Audio(); +export let audio = new Audio(); const NUMBER_OF_SONGS = 7; export function soundStart(){ @@ -23,7 +23,7 @@ export function soundtrack(){ ; }); - audio.addEventListener('ended', soundtrack); + audio.addEventListener('ended', setTimeout(soundtrack, rand(500,4000))); }, 1000); } diff --git a/scripts/ui/options.js b/scripts/ui/options.js index 11dbd16..95eb475 100644 --- a/scripts/ui/options.js +++ b/scripts/ui/options.js @@ -1,4 +1,5 @@ import { game } from "../../data/gameData.js"; +import { audio } from "../sound.js"; export function gameOptionsUI(){ const volumeValue = localStorage.getItem("mv-volume"); @@ -22,6 +23,7 @@ export function gameOptionsUI(){ const volumeEl = document.querySelector("#volume input"); volumeEl.addEventListener("change", () => { localStorage.setItem("mv-volume", volumeEl.value); + audio.volume = volumeEl.value; }); }