#TouhouDanmakufu[Plural]
	#ScriptVersion[3]
	#System["./tricky_system/Default_System.txt"]
	#Title["Vs Magechouli - Hard Mode"]
	#Text["She isn't Mima. Consider [r]yourself lucky."]
	#Image[""]
	#Background["./tricky_system/Default_Background_IceMountain.txt"]
	#Player["/script/player/", "./Ultima's DDC Reimu B/ReimuH.dnh"]
	let white = GetCurrentScriptDirectory~"sprites/white.png";
	let pldead = GetCurrentScriptDirectory~"sfx/se_pldead00.wav";
		let scream = GetCurrentScriptDirectory~"sfx/scream.wav";
	LoadTexture(white);
	let moo2 = false;
	let moo3 = false;
	let xcoord = 0;
	let sound3set = false;
	let soundset = false;
	let moo7 = false;
	let playx = GetStgFrameWidth/2;
	let playy = GetStgFrameHeight-32;
	let initx = 0;
	let inity = 0;
	let objSound;
	let obj = ObjEnemyBossScene_Create();
	let obj2 = ObjEnemyBossScene_Create();

	let obj3 = ObjEnemyBossScene_Create();
	let thunder = GetCurrentScriptDirectory~"sfx/thunder.wav";
	let vol = 95;
	let sound2set = false;
	let bossx = 0;
	let dir = GetCurrentScriptDirectory();
	let bossy = 0;
	let ycoord = 0;
	let moo = false;
	let maxlife = 0;
	let reimucut = GetCurrentScriptDirectory~"sprites/reimucut.png";
	let mimacut = GetCurrentScriptDirectory~"sprites/mimacut2.png";
	let kogasacut = GetCurrentScriptDirectory~"sprites/kogasacut.png";
	let kogasacut2 = GetCurrentScriptDirectory~"sprites/kogasacut2.png";
	let reimucut2 = GetCurrentScriptDirectory~"sprites/reimucut2.png";
	let mamizoucutmad = GetCurrentScriptDirectory~"sprites/mamizoucut.png";
	let mamizoucut = GetCurrentScriptDirectory~"sprites/mamizoucut2.png";
	let mimacut2 = GetCurrentScriptDirectory~"sprites/mimacutin3.png";
	let mimacutreal = GetCurrentScriptDirectory~"sprites/mimacut.png";
	let kogasacut3 = GetCurrentScriptDirectory~"sprites/kogasacutrekt.png";
	
	#include"./stage.eventdialogue.dnh"
	
	@Initialize
	{
LoadSound(pldead);
	LoadSound(thunder);
		LoadTexture(reimucut);
	LoadTexture(reimucut2);
	LoadTexture(mimacut);
	LoadTexture(mamizoucutmad);
		LoadTexture(mimacut2);
		LoadSound(scream);
		LoadTexture(mimacutreal);
	LoadTexture(kogasacut);
	LoadTexture(kogasacut3);
		LoadTexture(mamizoucut);
	SetPlayerLife(12);
	
		
		ObjEnemyBossScene_Add(obj, 0, dir ~ "MageN1_H.txt");
		ObjEnemyBossScene_Add(obj, 0, dir ~ "MageS1_H.txt");
		ObjEnemyBossScene_Add(obj, 1, dir ~ "MageN2_H.txt");
		ObjEnemyBossScene_Add(obj, 1, dir ~ "MageS2_H.txt");
		ObjEnemyBossScene_Add(obj, 2, dir ~ "MageN3_H.txt");
		ObjEnemyBossScene_Add(obj, 2, dir ~ "MageS3_H.txt");
		ObjEnemyBossScene_Add(obj, 5, dir ~ "MageN4_H.txt");
		ObjEnemyBossScene_Add(obj, 5, dir ~ "MageS4_H.txt");
		ObjEnemyBossScene_Add(obj, 4, dir ~ "MageN5_H.txt");
		ObjEnemyBossScene_Add(obj, 4, dir ~ "MageS5_H.txt");
		ObjEnemyBossScene_Add(obj, 3, dir ~ "MageN6_H.txt");
		ObjEnemyBossScene_Add(obj, 3, dir ~ "MageS6_H.txt");
		/*
		ObjEnemyBossScene_Add(obj, 6, dir ~ "MageS7_H.txt");
		ObjEnemyBossScene_Add(obj, 7, dir ~ "MageS8_H.txt");
		*/
		ObjEnemyBossScene_LoadInThread(obj);
	wait(30);
		TPlural();
	objSound = ObjSound_Create;
	ObjSound_Load(objSound, GetCurrentScriptDirectory~"bgm/bgm.ogg");
	}

	@MainLoop
	{
	  xcoord = GetCommonData("kogasax", GetStgFrameWidth/2)+32;
	   ycoord = GetCommonData("kogasay", 120);
	   if(xcoord>32){ bossx = xcoord; }
	   if(ycoord>0){ bossy = ycoord; }
		yield;
	}

	@Finalize
	{
	}

		

	@Event{
alternative(GetEventType())	
case(EV_PAUSE_ENTER)
{
if(soundset==true){
ObjSound_Stop(objSound);
}

}

case(EV_PAUSE_LEAVE)
{
if(soundset==true){
ObjSound_Play(objSound);
}

}


}

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

	task TPlural
	{
			
			wait(120);
		
		PlayMusic;
		ObjEnemyBossScene_Regist(obj);
			BottomEnemyMarker;
		wait(90);
		

		while(!Obj_IsDeleted(obj))
		{
			yield;
		}
		
		wait(180);
			
		CloseStgScene;
		CloseScript(GetOwnScriptID());
	}


task magiccircle2(size,type){ // draw magic circle
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let imgcircle=GetCurrentScriptDirectory~"sprites/MG.png";
	let spin = 0;
	let s = 0;
	LoadTexture(imgcircle);
	ObjPrim_SetTexture(obj,imgcircle);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,size,size,size);
	ObjRender_SetAlpha(obj,192);
	Obj_SetRenderPriorityI(obj, 28);
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	while(!Obj_IsDeleted(GetEnemyBossSceneObjectID)){
	spin += 2;
	ObjRender_SetAngleXYZ(obj,0,0,spin*2);
	ObjRender_SetPosition(obj,bossx-32,bossy,0);
	ObjRender_SetColor(obj,1*(192+42*sin(spin+180)),1*(192+42*sin(spin)),0);
	if(type==true){
	ObjRender_SetScaleXYZ(obj,size*1.1+0.1*sin(spin),size*1.1+0.1*sin(spin),0);
	}
	ObjMove_SetPosition(obj,bossx-32,bossy);
	yield;
	}
	Obj_Delete(obj);
	}


task BottomEnemyMarker{
  let imgnumber = GetCurrentScriptDirectory~"sprites/enemymarker.png";
  let objMarker = ObjPrim_Create(OBJ_SPRITE_2D);
  ObjRender_SetPosition(objMarker, GetStgFrameWidth/2, GetStgFrameHeight+32, 1); 
  ObjPrim_SetPrimitiveType(objMarker, PRIMITIVE_TRIANGLESTRIP);
  ObjRender_SetBlendType(objMarker, BLEND_ALPHA);
  Obj_SetRenderPriority(objMarker, 0.85);
  ObjPrim_SetTexture(objMarker, imgnumber);
  ObjRender_SetAlpha(objMarker, 255);
  ObjSprite2D_SetSourceRect(objMarker, 0, 0, 48, 16);
  ObjSprite2D_SetDestRect(objMarker, -25, -8, 25, 8);

 
  while(!Obj_IsDeleted(GetEnemyBossSceneObjectID)){
	
    ObjRender_SetPosition(objMarker, bossx, GetStgFrameHeight+24, 1);
	
    yield;
  }
  Obj_Delete(objMarker);
}
	
task PlayMusic{
	let rate = 100;
	//rate = 0;
	soundset = true;
	
	ObjSound_SetVolumeRate(objSound, rate);
	ObjSound_SetLoopEnable(objSound, true);
	ObjSound_SetRestartEnable(objSound, true);
	ObjSound_SetLoopSampleCount(objSound, 0, 5715528);
	ObjSound_SetSoundDivision(objSound, SOUND_BGM);
	ObjSound_Play(objSound);
	loop{
	if(moo3==true){
	ObjSound_SetFade(objSound, 2);
	loop(120){
	wait(1);
	ObjSound_SetVolumeRate(objSound, rate);
	rate-=100/140;
	}
	ObjSound_Stop(objSound);
	Obj_Delete(objSound);
	}
	
	yield;
	}
	}	