#TouhouDanmakufu[Plural]
	#ScriptVersion[3]
	#System["./tricky_system/Default_System.txt"]
	#Title["Trickysticks' Popular Popularity ~Original Mode~"]
	#Text["Original is equivalent to Hard, maybe?"]
	#Image[""]
	#Background["./tricky_system/Default_Background_IceMountain.txt"]
	#Player["/script/player/", "./Ultima's DDC Reimu B/ReimuH.dnh"]
	let white = GetCurrentScriptDirectory~"sprites/white.png";
	LoadTexture(white);
	let moo2 = false;
	let moo3 = false;
	let xcoord = 0;
	let sound3set = false;
	let moo7 = false;
	let playx = GetStgFrameWidth/2;
	let playy = GetStgFrameHeight-32;
	let initx = 0;
	let inity = 0;
	let objSound;
	let obj2 = ObjEnemyBossScene_Create();
	let obj3;
	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";

	#include"./stage.eventdialogue.dnh"
	
	@Initialize
	{
	SetPlayerLife(98);
	PlayMusic;
	TPlural();
	
	}

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

	@Finalize
	{
	}

		

	@Event{
alternative(GetEventType())	
case(EV_PAUSE_ENTER)
{
ObjSound_Stop(objSound);
}

case(EV_PAUSE_LEAVE)
{
ObjSound_Play(objSound);

}
}




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

	task TPlural
	{
			
			
			
			let obj = ObjEnemyBossScene_Create();
		ObjEnemyBossScene_Add(obj, 0, dir ~ "SakuyaN1_H.txt");
		ObjEnemyBossScene_Add(obj, 0, dir ~ "SakuyaS1_H.txt");
		ObjEnemyBossScene_Add(obj, 1, dir ~ "SakuyaN2_H.txt");
		ObjEnemyBossScene_Add(obj, 1, dir ~ "SakuyaS2_H.txt");
		ObjEnemyBossScene_Add(obj, 2, dir ~ "SakuyaN3_H.txt");
		ObjEnemyBossScene_Add(obj, 2, dir ~ "SakuyaS3_H.txt");
		ObjEnemyBossScene_Add(obj, 3, dir ~ "SakuyaS4_H.txt");
		ObjEnemyBossScene_LoadInThread(obj);
			wait(420);
		
		
		ObjEnemyBossScene_Regist(obj);
		wait(10);
		BottomEnemyMarker;
		magiccircle2(0.6, true);
		wait(90);
	
		while(!Obj_IsDeleted(obj))
		{
			yield;
		}
		
		wait(240);
		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)){
	if(GetCommonData("timestop", false)==false){
	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 ManipulatePlayer{
	initx = ObjMove_GetX(GetPlayerObjectID);
	inity = ObjMove_GetY(GetPlayerObjectID);
	 let incx = ((GetStgFrameWidth/2-initx)/60);
	let incy = (playy-inity)/60;
	loop(60){
	ObjMove_SetPosition(GetPlayerObjectID, ObjMove_GetX(GetPlayerObjectID)+incx, ObjMove_GetY(GetPlayerObjectID)+incy);
	yield;
	}
	loop{
	ObjMove_SetPosition(GetPlayerObjectID, GetStgFrameWidth/2, playy);
	yield;
	}
	}
	
	

function screenflash(r,g,b){
let time = 0;
let objWhite = ObjPrim_Create(OBJ_SPRITE_2D);

let alphavar = 0;

ObjPrim_SetTexture(objWhite, white);
ObjSprite2D_SetSourceRect(objWhite, 0, 0, 691, 607);
ObjSprite2D_SetDestCenter(objWhite);
ObjRender_SetColor(objWhite, r, g, b);
ObjRender_SetAlpha(objWhite, 127.5);
ObjMove_SetX(objWhite, GetStgFrameWidth/2);
ObjMove_SetY(objWhite, GetStgFrameHeight/2);
ObjRender_SetScaleXYZ(objWhite, 2, 2, 1);
loop(60){
	ObjRender_SetAlpha(objWhite, 125+125*sin(alphavar));
	if(time<=10){
	alphavar+=9;
	}
	if(time>=30){
	alphavar+=180/30;
	}
	wait2(1);
	time++;
	}
Obj_Delete(objWhite);
function wait2(w){ loop(w){ yield; } }
}
	
	
	
	


	task PlayMusic{
	let rate = 100;
	sound2set = true;
	objSound = ObjSound_Create;
	ObjSound_Load(objSound, GetCurrentScriptDirectory~"bgm/bgm.ogg");
	ObjSound_SetVolumeRate(objSound, 100);
	//ObjSound_SetVolumeRate(objSound, 0);
	ObjSound_SetLoopEnable(objSound, true);
	ObjSound_SetRestartEnable(objSound, true);
	ObjSound_SetLoopSampleCount(objSound, 1934604, 7226604);
	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;
	}
	}
	
	