#TouhouDanmakufu[Plural]
#ScriptVersion[3]
#Title["James"]
#Background["./background.txt"]
#Player["./player/Reimu Hakurei/Player_Reimu.txt"]


let bgm1= ObjSound_Create(); let bgm1Path = GetCurrentScriptDirectory ~ "./Byakuren.ogg";
let bgm2= ObjSound_Create(); let bgm2Path = GetCurrentScriptDirectory ~ "./gohan2.ogg";


task StartBGM(num){
    if(num==1){
		ObjSound_Load(bgm1, bgm1Path);
		ObjSound_SetVolumeRate(bgm1, 90);
		ObjSound_SetLoopEnable(bgm1, true);
		ObjSound_SetRestartEnable(bgm1, true);
		ObjSound_Play(bgm1);
	}
	else{
	    ObjSound_Load(bgm2, bgm2Path);
		ObjSound_SetVolumeRate(bgm2, 100);
		ObjSound_SetLoopEnable(bgm2, true);
		ObjSound_SetRestartEnable(bgm2, true);
		ObjSound_Play(bgm2);
	}
}

task FadeOutBGM(music) {
	descent(i in 0..10/9) {
		ObjSound_SetVolumeRate(music, i * 5/3);
		yield;
	}
	ObjSound_Stop(music);
}

 
@Event{
    alternative(GetEventType())
    case(EV_PAUSE_ENTER) {
		ObjSound_Stop(bgm1);
		ObjSound_Stop(bgm2);
	}
	case(EV_PAUSE_LEAVE) {
		ObjSound_Play(bgm1);
		ObjSound_Play(bgm2);
	}
	case(EV_USER_STAGE) {
		StartBGM(1);
	}
	case(EV_USER_STAGE + 1) {
	    FadeOutBGM(bgm1);
	}
	case(EV_USER_STAGE +2){
	    StartBGM(2);
	}
}


@Initialize{
    TPlural;
	SetPlayerLife(5);
	SetPlayerSpell(3);
}


@MainLoop{
    yield;
}


task TPlural{
    let dir = GetCurrentScriptDirectory()~ "./JamesSingles";
    let obj = ObjEnemyBossScene_Create();
	JamesName;
	
	ObjEnemyBossScene_Add(obj, 0, dir~"./intro.dnh");
	ObjEnemyBossScene_Add(obj, 0, dir ~ "./launch.dnh");
    ObjEnemyBossScene_Add(obj, 0, dir ~ "./Convergence.dnh");

	ObjEnemyBossScene_Add(obj, 1, dir ~ "./sine.dnh");
	ObjEnemyBossScene_Add(obj, 1, dir ~ "./spiral1.dnh");
	ObjEnemyBossScene_Add(obj, 1, dir ~ "./SInetime.dnh");
	
	ObjEnemyBossScene_Add(obj, 2, dir ~ "./spiral2.dnh");
	
	ObjEnemyBossScene_Add(obj, 3, dir ~ "./launchFit.dnh");
	ObjEnemyBossScene_Add(obj, 3, dir ~ "./Hahn-Banachstension.dnh");
	ObjEnemyBossScene_Add(obj, 3, dir ~ "./bgmFade.dnh");
	ObjEnemyBossScene_Add(obj, 3, dir ~ "./bgmChange.dnh");
	ObjEnemyBossScene_Add(obj, 3, dir~ "./mvt.dnh");
	
	ObjEnemyBossScene_Add(obj, 4, dir ~ "./Jamesrespite.dnh");
	ObjEnemyBossScene_Add(obj, 4, dir ~ "./Discontinuous.dnh");
	
	
	ObjEnemyBossScene_LoadInThread(obj);
    ObjEnemyBossScene_Regist(obj);
	while(!Obj_IsDeleted(obj)){yield;}
    CloseScript(GetOwnScriptID());
}



task JamesName{
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Prof James Robinson");
	ObjText_SetFontSize(objText, 15);
	ObjText_SetFontType(objText, "Arial");
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
		
	ObjText_SetMaxWidth(objText, 140);
	Obj_SetRenderPriorityI(objText, 70);
	ObjRender_SetPosition(objText, 5, 15, 1);
	
}