#TouhouDanmakufu[Plural]
#ScriptVersion[3]
#Title["best Jpatterns, maybe"]
#Text["attacks i made for fun, that[r]didn't fit in a specific battle"]
#Background["./BG.txt"]
#Player["./player/lenen/YabuKura.txt", "./player/lenen/TenkaBami.txt", "./player/gt_medicine/PracticeP.txt"]
#System["./System/Default_System.txt"]

let dir = GetCurrentScriptDirectory();
//
	let bgm = ObjSound_Create;
		ObjSound_Load(bgm, dir ~ "./lib/BGM/Boss.ogg");
		ObjSound_SetRestartEnable(bgm, true);
		ObjSound_SetVolumeRate(bgm, 100);
		ObjSound_SetLoopEnable(bgm, true);
		ObjSound_SetLoopTime(bgm, 0, 232.5);

//

@Initialize{
	ObjSound_Play(bgm);
	SetCommonData("music", true);
	
	TPlural;
	SetPlayerLife(5);
	SetPlayerSpell(3);
}

@Event{
	alternative(GetEventType())
	case(EV_PAUSE_ENTER){
		ObjSound_Stop(bgm);
	}
	case(EV_PAUSE_LEAVE){
		ObjSound_Play(bgm);
	}
}

@MainLoop{
	if(GetKeyState(KEY_A) == KEY_HOLD && GetKeyState(KEY_S) == KEY_PUSH){
		SetPlayerInvincibilityFrame(9999999);
	}
	if(GetKeyState(KEY_A) == KEY_HOLD && GetKeyState(KEY_D) == KEY_PUSH){
		SetPlayerInvincibilityFrame(0);
		DeleteShotInCircle(TYPE_ALL, TYPE_IMMEDIATE, GetPlayerX(), GetPlayerY(), 300);
	}
	yield;
}

task TPlural{
	SetForbidPlayerSpell(true);
	SetForbidPlayerShot(true);
	BGMName("BGM: Eternal Imitation Dance ~ Spell Collector");
	wait(60 * 4);
	
	loop(60){yield;}
	
	ObjSound_Play(bgm);
	
	let obj = ObjEnemyBossScene_Create(); 
		let N = []; let S = [];
		let num = 6;
		
	ascent(i in 0..num){
		N = N ~ [dir ~ "./scripts/Non" ~ vtos("02d", i+1) ~ ".txt"];
		S = S ~ [dir ~ "./scripts/Spell" ~ vtos("02d", i+1) ~ ".txt"];
	}
	
	//Line for Dialogue
	//ObjEnemyBossScene_Add(obj, 0, dir ~ "./lib/Dialogue/DialogueI.dnh"); 
	ascent(i in 0..num){	
		ObjEnemyBossScene_Add(obj, i, N[i]);
		ObjEnemyBossScene_Add(obj, i, S[i]);
	}
	
	ObjEnemyBossScene_LoadInThread(obj);
	ObjEnemyBossScene_Regist(obj);
	
	SetForbidPlayerSpell(false);
	SetForbidPlayerShot(false);
	while(!Obj_IsDeleted(obj)){
		yield;
	}
	
	CloseScript(GetOwnScriptID());
}

task BGMName(text){
	let objText = ObjText_Create();
	ObjText_SetText(objText, text);
	
	ObjText_SetFontSize(objText, 13);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText, 0, 0, 0);
	ObjText_SetFontBorderWidth(objText, 2);
	
	ObjText_SetMaxWidth(objText, 1337);
	
	Obj_SetRenderPriority(objText, 1);
	
	ObjRender_SetX(objText, GetStgFrameWidth/6);
	ObjRender_SetY(objText, GetStgFrameHeight);
	
	let y = 21;
	loop(30){
		ObjSound_SetRestartEnable(bgm, true);
		ObjRender_SetY(objText, ObjRender_GetY(objText)-(y/30));
		yield;
	}
	
	wait(60*3);
	
	loop(30){
		ObjRender_SetY(objText, ObjRender_GetY(objText)+(y/30));
		yield;
	}
	
	Obj_Delete(objText);
}

function wait(n){loop(n){yield;}}