let bgm;
let GCSD = GetCurrentScriptDirectory();
let path = GCSD ~ "bgm/a.mp3";
let sound = [];

@Initialize{
	sound = [
		CreateSound(GCSD ~ "/se/smbullet.wav"),	 	//Small Bullet; 			index = 0
		CreateSound(GCSD ~ "/se/labullet.wav"),	 	//Large Bullet; 			index = 1
		CreateSound(GCSD ~ "/se/spirit.wav"),	 	//Spirit Summon;	 		index = 2
		CreateSound(GCSD ~ "/se/damage1.wav"),	 	//Boss Damage 1; 			index = 3
		CreateSound(GCSD ~ "/se/damage2.wav"),	 	//Boss Damage 2; 			index = 4
		CreateSound(GCSD ~ "/se/timeout.wav"),		//Timeout warning; 			index = 5
		CreateSound(GCSD ~ "/se/timeout2.wav"),		//Timeout warning 2; 		index = 6
		CreateSound(GCSD ~ "/se/explode.wav"),		//Boooom;					index = 7
		CreateSound(GCSD ~ "/se/explodebig.wav"),	//Big badda boom;	 		index = 8
		CreateSound(GCSD ~ "/se/item.wav"),			//Item Pickup;	 			index = 6
		CreateSound(GCSD ~ "/se/extend.wav"),		//Extend!;					index = 7
		CreateSound(GCSD ~ "/se/bombget.wav"),		//You got a bomb;	 		index = 8
	];
	SetCommonData("SoundScript", GetOwnScriptID);
	BGM;
}

@Event{
    alternative(GetEventType())
    case(EV_PAUSE_ENTER){
        ObjSound_Stop(bgm);
    }
    case(EV_PAUSE_LEAVE){
		ObjSound_Play(bgm);
    }
	case(EV_USER){
		let arg = GetEventArgument(0);
		ObjSound_Play(sound[arg[0]]);
		ObjSound_SetVolumeRate(sound[arg[0]], arg[1]/2);
	}
}

function CreateSound(path){
	let obj = ObjSound_Create();
	ObjSound_Load(obj, path);
	ObjSound_SetVolumeRate(obj, 100);
	ObjSound_SetLoopEnable(obj, false);
	ObjSound_SetSoundDivision(obj, SOUND_SE);
	return obj;
}

task BGM{
	bgm	= ObjSound_Create();
	ObjSound_Load(bgm,GetCurrentScriptDirectory ~ "/bgm/a.mp3");
	ObjSound_SetSoundDivision(bgm,SOUND_BGM);
	ObjSound_SetVolumeRate(bgm,70);
	ObjSound_SetLoopEnable(bgm,true);
	ObjSound_SetLoopTime(bgm, 53.718, 60*2+41.037);
	ObjSound_SetRestartEnable(bgm, true);
	ObjSound_Play(bgm);
}