#TouhouDanmakufu[Stage]
#ScriptVersion[3]
#Title["Unexpected Master Mind - Letty Whiterock"]
#Text[" A Contest Entry [r] by Spectral Nexus"]
#Background["./Scene/Background.txt"]
#System["./System/Default_System.txt"]
#Player["./Player/Reimu/Reimu.txt"]

SetCommonData("Is Plural Script",true);
SetCommonData("Switch to Phase 2?",false);

@Initialize{
	Reset2DCamera;
	SetPlayerLife(99);
	SetPlayerSpell(3);
	Stage;
}

@MainLoop{
	yield;
}

@Finalize{
}


task Stage{
	let CSD = GetCurrentScriptDirectory();
	
	let pa = CSD ~ "Lib/STGBGM.ogg";
	let s = ObjSound_Create;
	ObjSound_Load(s,pa);
	ObjSound_SetSoundDivision(s,SOUND_BGM);
	ObjSound_SetVolumeRate(s,80);
	ObjSound_Play(s);
	
	let path = CSD ~ "Letty Plural.dnh";
	let path2 = CSD ~ "Kogasa Plural.dnh";
	let idScript = LoadScriptInThread(path);
	let idScript2 = LoadScriptInThread(path2);
	StartScript(idScript2);
	
	while(!IsCloseScript(idScript2)){
		yield;
	}
	Reset2DCamera;
	SetCommonData("Switch to Phase 2?",true);
	off;
	task off{
		loop(120){yield;}
		descent(i in 0..78){
			ObjSound_SetVolumeRate(s,i);
			loop(2){yield;}
		}
		ObjSound_Stop(s);
		Obj_Delete(s);
	}
	
	StartScript(idScript);
	
	while(!IsCloseScript(idScript)){
		yield;
	}
	loop(400){yield;}
	Reset2DCamera;

	CloseStgScene();
	}