#TouhouDanmakufu[Plural]
#ScriptVersion[3]
#System["./default_system/Default_System.txt"]
#Title["A Tiny, Tiny, Clever Commander"]
#Text["Nazrin Battle"]
#Player["./player/Sanae Kochiya/Player_Sanae.txt"]
#Background["./background.txt"]

#include".\Resources.txt"
#include".\selibrary.txt"

let obj=ObjEnemyBossScene_Create();

let music = ObjSound_Create;
ObjSound_Load(music,CSD ~ "./se/bgm.mp3");
ObjSound_SetLoopEnable(music,true);

@Initialize{
	TPlural;
	SetAutoDeleteObject(true);
	SetPlayerLife(4);
	SetPlayerSpell(3);
	SetPauseScriptPath(CSD ~ "./default_system/Default_Pause.txt");
	SetEndSceneScriptPath(CSD ~ "./default_system/Default_EndScene.txt");
	InstallFont(CSD ~ "./default_system/Cirno.ttf");
	InstallFont(CSD ~ "./default_system/Revue.ttf");
	InstallFont(CSD ~ "./default_system/BNKGOTHM.TTF");
}

@Event{
	
}

@MainLoop{
	yield;
}

task TPlural
{
	let CSD=GetCurrentScriptDirectory();

	Select;
	wait(20);
	while(GetVirtualKeyState(VK_OK) == KEY_FREE || GetVirtualKeyState(VK_OK) == KEY_HOLD){yield;}
	ObjSound_Play(music);
	ObjSound_SetVolumeRate(music,100);
	Difficulty;
	BossName;
	ObjEnemyBossScene_Add(obj,0,CSD~"n1.txt");
	ObjEnemyBossScene_Add(obj,0,CSD~"s1.txt");
	ObjEnemyBossScene_Add(obj,1,CSD~"n2.txt");
	ObjEnemyBossScene_Add(obj,1,CSD~"s2.txt");
	ObjEnemyBossScene_Add(obj,2,CSD~"n3.txt");
	ObjEnemyBossScene_Add(obj,2,CSD~"s3.txt");
	ObjEnemyBossScene_Add(obj,2,CSD~"end.txt");
	
	ObjEnemyBossScene_LoadInThread(obj);
	ObjEnemyBossScene_Regist(obj);
	while(!Obj_IsDeleted(obj))
	{
		yield;
	}
	End;
}

task Select{

		let objTitle = ObjText_Create();
			Obj_SetRenderPriorityI(objTitle, 80);
			ObjText_SetFontType(objTitle, "Cirno");
			ObjText_SetFontSize(objTitle, 36);
			ObjText_SetFontBorderType(objTitle, BORDER_FULL);
			ObjText_SetFontBorderWidth(objTitle, 3);
			ObjText_SetFontBorderColor(objTitle, 0,0,0);
			ObjText_SetFontColorTop(objTitle, 255,255,255);
			ObjText_SetFontColorBottom(objTitle, 128,128,128);
			ObjText_SetMaxWidth(objTitle, 500);
			ObjRender_SetPosition(objTitle,GetStgFrameWidth/2-100,GetStgFrameHeight/2-120,0);
			ObjText_SetText(objTitle, "Select a Difficulty:");
			
		let objMessage = ObjText_Create();
			Obj_SetRenderPriorityI(objMessage, 80);
			ObjText_SetFontType(objMessage, "Cirno");
			ObjText_SetFontSize(objMessage, 36);
			ObjText_SetFontBorderType(objMessage, BORDER_FULL);
			ObjText_SetFontBorderWidth(objMessage, 3);
			ObjText_SetFontBorderColor(objMessage, 0,0,0);
			ObjText_SetFontColorTop(objMessage, 255,255,255);
			ObjText_SetFontColorBottom(objMessage, 128,128,128);
			ObjText_SetMaxWidth(objMessage, 500);
			ObjRender_SetPosition(objMessage,GetStgFrameWidth/2-100,GetStgFrameHeight/2-10,0);

		let difficulty = 1;
		let CHOSEN = false;
		let objText = ObjText_Create();
			Obj_SetRenderPriorityI(objText, 80);
			ObjText_SetFontType(objText, "Cirno");
			ObjText_SetFontSize(objText, 36);
			ObjText_SetFontBorderType(objText, BORDER_FULL);
			ObjText_SetFontBorderWidth(objText, 3);
			ObjText_SetFontBorderColor(objText, 0,0,0);
			ObjText_SetFontColorTop(objText, 255,255,255);
			ObjText_SetFontColorBottom(objText, 255,0,255);
			ObjText_SetMaxWidth(objText, 500);
			ObjRender_SetPosition(objText,GetStgFrameWidth/2-80,GetStgFrameHeight/2-60,0);
			ObjText_SetText(objText, "Difficulty: Easy");
		
		while(!CHOSEN){
			if(GetVirtualKeyState(VK_RIGHT)==KEY_PUSH){SE_Play(Choose, 50);
			difficulty++;}
			
			else if(GetVirtualKeyState(VK_LEFT)==KEY_PUSH){SE_Play(Choose, 50);
			difficulty--;}
			
			else if(GetVirtualKeyState(VK_SHOT)==KEY_PUSH){SE_Play(Confirm, 50);
			SetCommonData("Difficulty",difficulty);
			CHOSEN = true;}
		if(difficulty==1){
		ObjText_SetText(objText, "Difficulty: Easy");
		ObjText_SetFontColorBottom(objText, 0,255,0);
		ObjText_SetText(objMessage, "For People who is [r]not good at this");
		}
		if(difficulty==2){
		ObjText_SetText(objText, "Difficulty: Normal");
		ObjText_SetFontColorBottom(objText, 0,0,255);
		ObjText_SetText(objMessage, "For People who enjoy[r]this type of games");
		}		
		if(difficulty==3){
		ObjText_SetText(objText, "Difficulty: Hard");
		ObjText_SetFontColorBottom(objText, 172,0,249);
		ObjText_SetText(objMessage, "For the Cool People");
		}
		if(difficulty==4){
		ObjText_SetText(objText, "Difficulty: Lunatic");
		ObjText_SetFontColorBottom(objText, 255,0,0);
		ObjText_SetText(objMessage, "For Gensokyo's [r]Old Ones");
		}
		if(difficulty>4){difficulty=1;}
		if(difficulty<1){difficulty=4;}
		yield;}
		Obj_Delete(objText);
		Obj_Delete(objMessage);
		Obj_Delete(objTitle);
}

task Difficulty{
		let objTitle = ObjText_Create();
		Obj_SetRenderPriorityI(objTitle, 100);
		ObjText_SetFontType(objTitle, "Revue");
		ObjText_SetFontSize(objTitle, 30);
		ObjText_SetFontBorderType(objTitle, BORDER_FULL);
		ObjText_SetFontBorderWidth(objTitle, 3);
		ObjText_SetFontBorderColor(objTitle, 0,0,0);
		ObjText_SetFontColorTop(objTitle, 255,255,255);
		ObjText_SetFontColorBottom(objTitle, 255,255,255);
		ObjText_SetMaxWidth(objTitle, 500);
		ObjRender_SetPosition(objTitle,480,10,0);
		if(GetCommonData("Difficulty",1)==1){
		ObjText_SetFontBorderColor(objTitle, 0,255,0);
		ObjText_SetText(objTitle, "Easy");}
		if(GetCommonData("Difficulty",1)==2){
		ObjText_SetFontBorderColor(objTitle, 0,0,255);
		ObjText_SetText(objTitle, "Normal");}
		if(GetCommonData("Difficulty",1)==3){
		ObjText_SetFontBorderColor(objTitle, 255,0,255);
		ObjText_SetText(objTitle, "Hard");}
		if(GetCommonData("Difficulty",1)==4){
		ObjText_SetFontBorderColor(objTitle, 255,0,0);
		ObjText_SetText(objTitle, "Lunatic");}
}


task BossName{
	let objtext = ObjText_Create;
	
	ObjText_SetFontSize(objtext,12);
	ObjText_SetFontType(objtext, "Bank Gothic MD");
	// ObjText_SetFontBold(objtext, true);
	ObjText_SetFontColorTop(objtext,255,255,255);
	ObjText_SetFontColorBottom(objtext,255,0,0);
	ObjText_SetFontBorderType(objtext,BORDER_FULL);
	ObjText_SetFontBorderWidth(objtext,1);
	ObjText_SetFontBorderColor(objtext,0,0,0);
	ObjText_SetHorizontalAlignment(objtext,ALIGNMENT_LEFT);
	ObjText_SetMaxWidth(objtext,400);
	Obj_SetRenderPriorityI(objtext,65);
	
	let objEnemy = ID_INVALID;
	let alpha = 0;
	
	while(!Obj_IsDeleted(obj)){
		if(length(GetEnemyBossObjectID)>0) { objEnemy = GetEnemyBossObjectID[0]; }
		ObjRender_SetAlpha(objtext,alpha);
		ObjText_SetText(objtext,"Nazrin");
		ObjRender_SetPosition(objtext,5,18,0);
		if(alpha<255 && GetPlayerY>=115) { alpha+=255/30; }
		if(alpha>150 && GetPlayerY<115) { alpha-=255/30; }
		yield;
	}
	Obj_Delete(objtext);
}

task End{
		let objTitle = ObjText_Create();
			Obj_SetRenderPriorityI(objTitle, 80);
			ObjText_SetFontType(objTitle, "Cirno");
			ObjText_SetFontSize(objTitle, 36);
			ObjText_SetFontBorderType(objTitle, BORDER_FULL);
			ObjText_SetFontBorderWidth(objTitle, 3);
			ObjText_SetFontBorderColor(objTitle, 0,0,0);
			ObjText_SetFontColorTop(objTitle, 255,255,255);
			ObjText_SetFontColorBottom(objTitle, 128,128,128);
			ObjText_SetMaxWidth(objTitle, 500);
			ObjRender_SetPosition(objTitle,GetStgFrameWidth/4,GetStgFrameHeight/2-120,0);
			ObjText_SetText(objTitle, "You Win!!!");
	wait(60);
			let objText = ObjText_Create();
			Obj_SetRenderPriorityI(objText, 80);
			ObjText_SetFontType(objText, "Cirno");
			ObjText_SetFontSize(objText, 36);
			ObjText_SetFontBorderType(objText, BORDER_FULL);
			ObjText_SetFontBorderWidth(objText, 3);
			ObjText_SetFontBorderColor(objText, 0,0,0);
			ObjText_SetFontColorTop(objText, 255,255,255);
			ObjText_SetFontColorBottom(objText, 128,128,128);
			ObjText_SetMaxWidth(objText, 500);
			ObjRender_SetPosition(objText,GetStgFrameWidth/4,GetStgFrameHeight/2-70,0);
		if(GetCommonData("Difficulty",1)==1){
		ObjText_SetText(objText, "Difficulty: Easy");}
		if(GetCommonData("Difficulty",1)==2){
		ObjText_SetText(objText, "Difficulty: Normal");}
		if(GetCommonData("Difficulty",1)==3){
		ObjText_SetText(objText, "Difficulty: Hard");}
		if(GetCommonData("Difficulty",1)==4){
		ObjText_SetText(objText, "Difficulty: Lunatic");}
	wait(120);
	    CloseScript(GetOwnScriptID()); 
}