let BGMLoad = [
	CreateBGM("bgm1",3,60*2+0),
	CreateBGM("bgm2",0,60*4+29),
];
let BGMNameList = [
	"On The Way To The Starry Sky",
	"Hartmann's Youkai Girl (House Set of SA)",
];
let BGMTextList = [
	"This BGM is cool. [r]And I chose it.",
	"This BGM is cool, [r]And I chose it.",
];
let soundLoad = [

	CreateSE("se_spell_0"), // 0
	CreateSE("se_endtime"), // 1
	CreateSE("se_obtain"), // 2
	CreateSE("se_fail"), // 3

	CreateSE("se_cursor_00"), // 4
	CreateSE("se_cursor_01"), // 5
	CreateSE("se_cursor_03"), // 6
	CreateSE("se_stop_02"), // 7
	CreateSE("se_stop_03"), // 8

	CreateSE("se_1up"), // 9
	CreateSE("se_item"), // 10
	CreateSE("se_talk_00"), // 11
	CreateSE("se_warning"), // 12

	CreateSE("se_ch00"), // 13
	CreateSE("se_ch02"), // 14
	CreateSE("se_charge_00"), // 15

	CreateSE("se_enemy_death"), // 16
	CreateSE("se_boss_d"), // 17
	CreateSE("se_boss_end"), // 18

	CreateSE("se_plst00"), //19
	CreateSE("se_thrill"),//20
	CreateSE("se_barrier"),//21
	CreateSE("se_hit"),//22
	CreateSE("se_spell"),//23
	CreateSE("se_chargeid"),//24
	CreateSE("se_flash_00"), // 25

	CreateSE("se_shot_01"), // 26
	CreateSE("se_shot_00"), // 27
	CreateSE("se_slash"), // 28
	CreateSE("se_shot_00"), // 39
 
];
let bgmState = 0;

function CreateSE(patfil){
	let obj = ObjSound_Create();
	ObjSound_Load(obj, GetCurrentScriptDirectory ~ "./../../se/" ~ patfil ~ ".wav");
	ObjSound_SetSoundDivision(obj,SOUND_SE);
	return obj;
}
function CreateBGM(patfil,tim1,tim2){
	let obj = ObjSound_Create();
	ObjSound_Load(obj, GetCurrentScriptDirectory ~ "./../../se/" ~ patfil ~ ".ogg");
	ObjSound_SetSoundDivision(obj,SOUND_BGM);
	ObjSound_SetLoopEnable(obj,true);
	ObjSound_SetLoopTime(obj,tim1,tim2);
	ObjSound_SetVolumeRate(obj,50);
	return obj;
}

task BGMControl(){
	LoadCommonDataAreaA2("Data",GetCurrentScriptDirectory ~ "data.dat");
	if(!IsCommonDataAreaExists("Data")){
		CreateCommonDataArea("Data");
		SetAreaCommonData("Data","BGM",85);
		SetAreaCommonData("Data","SE",85);
		SaveCommonDataAreaA2("Data",GetCurrentScriptDirectory ~ "data.dat");
	}
	loop{
		ascent(a in 0..length(BGMLoad)){
			if(a+1 == bgmState){
				let st = bgmState;
				ObjSound_Play(BGMLoad[bgmState-1]);     
				ObjSound_SetRestartEnable(BGMLoad[st-1],true);                                          
				while(a+1 == bgmState){
					ObjSound_SetVolumeRate(BGMLoad[bgmState-1],GetAreaCommonData("Data","BGM",85));
					yield;
				}
				ObjSound_Stop(BGMLoad[st-1]);
				ObjSound_SetRestartEnable(BGMLoad[st-1],false);
			}
		}
		yield;
	}
}