
var isMuted = false
var isBgMenuMusicPlaying = false;

function loadAudio() {
    Crafty.audio.add({
        BgmMenu: [
            "audio/Derby - menu tune (mastered).ogg",
        ],

        GameMusic: [
            "audio/gameplay.ogg",
        ],
                 
        LevelComplete: [
            "audio/win game.ogg",
        ],
        
        LevelLost: [
            "audio/lost game.ogg",
        ],
     
    });
    console.log("AAAUUUUUUUDDDDDDDDDDDIIIIIIIIIIIOOOOOOOOOOO LOADED")

}


function setAudioIsMuted(pBool) {
    isMuted = pBool
}

			
function getAudioIsMuted() {
    return isMuted
}
			
//the following function will convert all floating point numbers to integers example 3.99 to 3
function playSfxAudio(pAudioName) {
    if(isMuted) {  return true; }
    if(pAudioName==undefined) return true;
    Crafty.audio.play(pAudioName)
			
}

function playBgMusic(pAudioName) {
    if(isMuted) {
		return true;
	}
    if(pAudioName==undefined) return true;
    if(pAudioName=="BgmMenu" ) { 
        if(isBgMenuMusicPlaying) {
			return true ; 
		} 
		else { 
			isBgMenuMusicPlaying=true;
		}
    }
    Crafty.audio.stop();
    Crafty.audio.play(pAudioName, -1)
}
			
function setBgMusicPlaying() {
    isBgMenuMusicPlaying=false;
}

