#TouhouDanmakufu[Plural]
#ScriptVersion[3]
#Title["Kurohebi Boss Fight by JDude"]
#Text[""]
#Background["./BG.txt"]
#Player["./player/ln/YK.txt", "./player/ln/YS.txt", "./player/gt_medicine/PracticeP.txt"]
#System["./System/Default_System.txt"]

let dir = GetCurrentScriptDirectory();
let isBattle = false;
//
	let bgm = ObjSound_Create;
		ObjSound_Load(bgm, dir ~ "./lib/BGM/wwafawdwg.ogg");
		ObjSound_SetRestartEnable(bgm, true);
		ObjSound_SetVolumeRate(bgm, 85);
		ObjSound_SetLoopEnable(bgm, true);
//

@Initialize{
	ObjSound_Play(bgm);
	
	Difficult(2);
	SetCommonData("set_dif", true);
	SetCommonData("music", true);
		
	TPlural;
	SetPlayerLife(4);
	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_PUSH && GetKeyState(KEY_S) == KEY_HOLD){
		SetPlayerInvincibilityFrame(9999999);
	}
	yield;
}

task TPlural{
	BGMName("BGM - Melanin in Black ~ Colt Snake");
	wait(60 * 4);
	
	loop(60){yield;}
	
	ObjSound_Play(bgm);
	
	let obj = ObjEnemyBossScene_Create();
		let n = [];
		let s = [];
		
	let num = 3;
	
	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"];
	}
	
	ascent(i in 0..num){	
		ObjEnemyBossScene_Add(obj, i, n[i]);
		ObjEnemyBossScene_Add(obj, i, s[i]);
	}
	
	ObjEnemyBossScene_LoadInThread(obj);
	ObjEnemyBossScene_Regist(obj);
	
	while(!Obj_IsDeleted(obj)){
		yield;
	}
	
	CloseScript(GetOwnScriptID());
}

task BGMName(text){
	let objText = ObjText_Create();
	ObjText_SetText(objText, text);
	
	ObjText_SetFontSize(objText, 10);
	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, 0.01);
	
	ObjRender_SetX(objText, 31);
	ObjRender_SetY(objText, GetStgFrameHeight+40);
	
	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);
}

task Difficult(num){
	let pic = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(pic, GetCurrentScriptDirectory() ~ "lib/FX/diffs.png");
	ObjSprite2D_SetSourceRect(pic, 0, 59, 165, 86);
	alternative(num)
		case(0){ObjSprite2D_SetSourceRect(pic, 0, 0, 161, 27);} //Easy
		case(1){ObjSprite2D_SetSourceRect(pic, 0, 29, 208, 56);} //Normal
		case(2){ObjSprite2D_SetSourceRect(pic, 0, 59, 165, 86);} //Hard
		case(3){ObjSprite2D_SetSourceRect(pic, 0, 88, 200, 115);} //Unreal
		case(4){ObjSprite2D_SetSourceRect(pic, 0, 122, 183, 174);} //Easy Ex
		case(5){ObjSprite2D_SetSourceRect(pic, 0, 183, 178, 203);} //Ex
		case(6){ObjSprite2D_SetSourceRect(pic, 0, 212, 184, 270);} //Ex+a
	ObjSprite2D_SetDestCenter(pic);
	ObjRender_SetBlendType(pic, BLEND_ALPHA);
	ObjRender_SetScaleXYZ(pic, 1, 1, 0);
	Obj_SetRenderPriority(pic, 1);
	
	ObjRender_SetPosition(pic, 530, GetScreenHeight() - 50, 0);
}

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