let Cut = GetCurrentScriptDirectory~"sprites\Cut.png";
let imageFile = GetCurrentScriptDirectory~"sprites\sakuya.png";
let imageFile2 = GetCurrentScriptDirectory~"sprites\fan.png";
let background = GetCurrentScriptDirectory~"sprites\background.png";
let f = true;
let poof = GetCurrentScriptDirectory~"sfx\poof.wav";
let timestop = GetCurrentScriptDirectory~"sfx\timestop.wav";
let variation = 1;
let one = 1;
let last = false;
let drift = false;
let variable = 1;
let futo = GetCurrentScriptDirectory~"sprites\futo.png";
let frame = -60;
let shooting = false;
let frame2 = -60;
let familiarspawn = GetCurrentScriptDirectory~"sfx\Shadow.wav";
let die = GetCurrentScriptDirectory~"sfx\se_enep01.wav";
let dream = GetCurrentScriptDirectory~"sfx\dream.wav";
let frame3 = -60;
let slash = GetCurrentScriptDirectory~"sfx\slash.wav";
let border = GetCurrentScriptDirectory~"sfx\border.wav";
let orb = GetCurrentScriptDirectory~"sfx\orb.wav";
let shot3 = GetCurrentScriptDirectory~"sfx\shot3.wav";
let shot4 = GetCurrentScriptDirectory~"sfx\shot4.wav";
let shot2 = GetCurrentScriptDirectory~"sfx\shot2.wav";
let shot = GetCurrentScriptDirectory~"sfx\shot.wav";
let charge = GetCurrentScriptDirectory~"sfx\Charge.wav";
let wtf = GetCurrentScriptDirectory~"sfx\kira00.wav";
let b = 0;
let timer = GetTimer;
let alpha = 255;
let timer2 = 0;
let time1 = GetCurrentScriptDirectory~"sfx\time1.wav";
let time2 = GetCurrentScriptDirectory~"sfx\time2.wav";
let teleport = GetCurrentScriptDirectory~"sfx\teleport.wav";
let caution = GetCurrentScriptDirectory~"sfx\caution.wav";
let acc1 = 0;
let ping = GetCurrentScriptDirectory~"sfx\ping.wav";
let acc2 = 0;
let acc3 = 0;
let acc5 = 0;
let TimeStopped = false;
let ang = 0;
let anim1 = 0;
let yy = 0;
let YuyukoSensu_SizeX = 0;
 let YuyukoSensu_SizeY = 1/20;
let c = 0;
let angle = 0;
let anim2 = 0;
let anim3 = 0;
let radius = 0;
let angle = 0;
let decidedangle = rand(0, 360);
let CBG1 = GetCurrentScriptDirectory~"sprites\CBG1.png";
let CBG2 = GetCurrentScriptDirectory~"sprites\CBG2.png";
let ang = 0;
let shot3 = GetCurrentScriptDirectory~"sfx\shot3.wav";
let objbullets = [];
let objgrowers = [];
let variation = 0;
let imglifebar = GetCurrentScriptDirectory~"lifebar_thWW.png";
let familiarspawn = GetCurrentScriptDirectory~"sfx\Shadow.wav";
let bgm = GetCurrentScriptDirectory~"mu\bgm.mp3";
let SP = GetCurrentScriptDirectory~"sprites\futo.png";
let laser = GetCurrentScriptDirectory~"sfx\laser.wav";
let MC = GetCurrentScriptDirectory~"sprites\NMC.png";
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	#include_function ".\cutin.dnh"
	#include_function ".\DATA\lib_anime_Sakuya.dnh"
	@MainLoop{
	
	if(GetTimer!=timer && (GetTimer < 10 && GetTimer>3)){
		PlaySE(time1);
			}

	if(GetTimer!=timer && GetTimer < 4){
		PlaySE(time2);
	

	
			}
	timer = GetTimer;
	if(TimeStopped==true){
	SetTimer(timer2);
	}
	
	
			SetCollisionB(GetX, GetY, 14.5); 
			if(OnEnemySpell==false){
	                SetCollisionA(GetX, GetY, 32); 
			}
			alpha=255;
			
		if(GetTimeOfPlayerInvincibility>0 && OnEnemySpell==true){
		alpha=120;
		 SetCollisionA(GetX+5000, GetY+5000, 32); 
		}

		if(GetTimeOfPlayerInvincibility<=0 && OnEnemySpell==true){
		alpha=255;
		 SetCollisionA(GetX, GetY, 32); 
		}
	
	yield;


	
	}

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


task ModeBullet(x, y, v, angle, accel, maxspeed, graphic, delay){
		let obj = Obj_Create(OBJ_SHOT);
		let f = 0;
		
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, v);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDelay(obj, delay);
		Obj_SetAutoDelete(obj, true);
		while(!Obj_BeDeleted(obj)){
			if(TimeStopped==true){
				if(f==0){
					ChangeMode(rand_int(0, 6));
					Obj_SetSpeed(obj, 0);
					f++;
					
					
				}
			}else{
				if(Obj_GetSpeed(obj)<maxspeed){
					Obj_SetSpeed(obj, Obj_GetSpeed(obj)+accel);
				}
				if(Obj_GetSpeed(obj)>=maxspeed){
					Obj_SetSpeed(obj, maxspeed);
				}
	
			}
			yield;
		}
		
		function ChangeMode(mode){
			wait(rand_int(0, 60));
			if(mode==1){
				ObjShot_SetGraphic(obj, WHITE32);
				Obj_SetAngle(obj, atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX+rand(-20, 20) - Obj_GetX(obj)));
			}
			if(mode==2 || mode==4 || mode==0){
				ObjShot_SetGraphic(obj, RED32);
				Obj_SetAngle(obj, rand_int(0, 359));
			}
			if(mode==3){
				ObjShot_SetGraphic(obj, GREEN32);
				Obj_SetAngle(obj, Obj_GetAngle(obj)+rand(-20, 20));
				Obj_SetSpeed(obj, Obj_GetSpeed(obj)+2);
			}

			if(mode==5){
			ObjShot_SetGraphic(obj, YELLOW32);
			Obj_SetAngle(obj, Obj_GetAngle(obj)-180);
		}
else{
				
			}
		}
	}




task CreateShot01v(x, y, v, angle, accel, maxspeed, graphic, delay){
		let obj = Obj_Create(OBJ_SHOT);
		let f = 0;
		let moo = 0;
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, v);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic);
		//ObjShot_SetDelay(obj, delay);
		Obj_SetAutoDelete(obj, true);
		while(!Obj_BeDeleted(obj)){
			if(TimeStopped==true){
				if(f==0){
					ChangeMode(1);
					Obj_SetSpeed(obj, 0);
					f++;
					
					
				}
			}else{
				
	
			}
			yield;
		}
		
		function ChangeMode(mode){
			wait(rand_int(0, 60));
			if(mode==1){
			if(delay!=1){
				loop(8){
				CreateShot01(Obj_GetX(obj)+20*cos(atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo), Obj_GetY(obj)+20*sin(atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo), 2.4, atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo, BLUE31, 30);
				CreateShot01(Obj_GetX(obj)+20*cos(atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo), Obj_GetY(obj)+20*sin(atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo), 1.4, atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo, BLUE31, 30);
				CreateShot01(Obj_GetX(obj)+20*cos(atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo), Obj_GetY(obj)+20*sin(atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo), 0.75, atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo, BLUE31, 30);
				moo+=360/8;
				}
			}
			if(delay==1){
				loop(8){
				CreateShot01(Obj_GetX(obj)+20*cos(atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj))+moo), Obj_GetY(obj)+20*sin(atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj))+moo), 2.5, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj))+moo, GREEN31, 30);
				CreateShot01(Obj_GetX(obj)+20*cos(atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj))+moo), Obj_GetY(obj)+20*sin(atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj))+moo), 2, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj))+moo, GREEN31, 30);
				CreateShot01(Obj_GetX(obj)+20*cos(atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj))+moo), Obj_GetY(obj)+20*sin(atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj))+moo), 1.5, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj))+moo, GREEN31, 30);
				CreateShot01(Obj_GetX(obj)+20*cos(atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo), Obj_GetY(obj)+20*sin(atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo), 0.75, atan2(GetEnemyY-Obj_GetY(obj), GetEnemyX-Obj_GetX(obj))+moo+rand(-20, 20), BLUE31, 30);
				moo+=360/8;
				}
			}
			
			Obj_Delete(obj);
			}
			if(mode==2 || mode==4 || mode==0){
				ObjShot_SetGraphic(obj, RED32);
				Obj_SetAngle(obj, rand_int(0, 359));
			}
			if(mode==3){
				ObjShot_SetGraphic(obj, GREEN32);
				Obj_SetAngle(obj, rand(0, 450));
				Obj_SetSpeed(obj, Obj_GetSpeed(obj)+2);
			}

			if(mode==5){
			ObjShot_SetGraphic(obj, WHITE32);
			Obj_SetAngle(obj, Obj_GetAngle(obj)-180);
		}
else{
				
			}
		}
	}

function Bundles(y){
	PlaySE(shot);
	loop(12){
	ascent(i in 0..8){
	ModeBullet(GetX, GetY, 1.5-(i/8), (90+angle+(i*5))*one, 0.01, 3, BLUE32, i);
	}
	angle+=360/12;
	}
	
	 }


 task CreateShotReflect(x, y, v, ang, graphic, delay, offset) {
		let obj_id = Obj_Create(OBJ_SHOT); let border = 10; let  counter = 0;
		Obj_SetPosition(obj_id, x, y);
		ObjShot_SetGraphic(obj_id, graphic);
		Obj_SetSpeed(obj_id, v); Obj_SetAngle(obj_id, ang); ObjShot_SetDelay(obj_id, delay);
		while(!Obj_BeDeleted(obj_id)) {
			if(counter <= 1) {
				
				//if(Obj_GetX(obj_id) > GetClipMaxX+border) {  Obj_SetX(obj_id, 2*(GetClipMaxX+border)-Obj_GetX(obj_id)); Obj_SetAngle(obj_id, 180-Obj_GetAngle(obj_id)+rand(-offset, offset)); counter+=2; }
				//else if(Obj_GetX(obj_id) < GetClipMinX-border) { Obj_SetX(obj_id, 2*(GetClipMinX-border)-Obj_GetX(obj_id)); Obj_SetAngle(obj_id, 180-Obj_GetAngle(obj_id)+rand(-offset, offset)); counter+=2; }
				if(Obj_GetY(obj_id) < GetClipMinY-border) {  Obj_SetY(obj_id, 2*(GetClipMinY-border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)+rand(-offset, offset)); counter+=1; }
				//else if(Obj_GetY(obj_id) > GetClipMaxY+border) { Obj_SetY(obj_id, 2*(GetClipMaxY+border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)+rand(-offset, offset)); counter+=1; }
			}
			yield;
		}
	}


 task CreateShotReflect2(x, y, v, ang, graphic, delay, offset) {
		let obj_id = Obj_Create(OBJ_SHOT); let border = 10; let  counter = 0;
		Obj_SetPosition(obj_id, x, y);
		ObjShot_SetGraphic(obj_id, graphic);
		Obj_SetSpeed(obj_id, v); Obj_SetAngle(obj_id, ang); ObjShot_SetDelay(obj_id, delay);
		while(!Obj_BeDeleted(obj_id)) {
			if(counter <= 1) {
				
				if(Obj_GetX(obj_id) > GetClipMaxX+border) {  Obj_SetX(obj_id, 2*(GetClipMaxX+border)-Obj_GetX(obj_id)); Obj_SetAngle(obj_id, 180-Obj_GetAngle(obj_id)+rand(-offset, offset)); counter+=2; }
				else if(Obj_GetX(obj_id) < GetClipMinX-border) { Obj_SetX(obj_id, 2*(GetClipMinX-border)-Obj_GetX(obj_id)); Obj_SetAngle(obj_id, 180-Obj_GetAngle(obj_id)+rand(-offset, offset)); counter+=2; }
				if(Obj_GetY(obj_id) < GetClipMinY-border) {  Obj_SetY(obj_id, 2*(GetClipMinY-border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)+rand(-offset, offset)); counter+=1; }
				//else if(Obj_GetY(obj_id) > GetClipMaxY+border) { Obj_SetY(obj_id, 2*(GetClipMaxY+border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)+rand(-offset, offset)); counter+=1; }
			}
			yield;
		}
	}


sub ExMove { ExMove_(GetClipMinY+120, 10, rand(15, 30)); }
function ExMove_(height, ud, length) {
	SetAction(ACT_MOVE, 180);
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length+20, rand(height+4 - ud, height + ud), 20, 2);
		} else {
			SetMovePosition03(GetX - length-20, rand(height - ud, height + ud), 20, 2);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length-20, rand(height - ud, height + ud), 20, 2);
		} else {
			SetMovePosition03(GetX + length+20, rand(height - ud, height + ud), 20, 2);
		}
	}
}

sub ExMoveLower { ExMoveL_(GetClipMinY+150, 10, rand(15, 30)); }
function ExMoveL_(height, ud, length) {
	SetAction(ACT_MOVE, 180);
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length+20, rand(height+4 - ud, height + ud), 20, 2);
		} else {
			SetMovePosition03(GetX - length-20, rand(height - ud, height + ud), 20, 2);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length-20, rand(height - ud, height + ud), 20, 2);
		} else {
			SetMovePosition03(GetX + length+20, rand(height - ud, height + ud), 20, 2);
		}
	}
}

sub ExMove2 { ExMove_2(GetClipMinY+120, 0, rand(20, 40)); }
function ExMove_2(height, ud, length) {
	SetAction(ACT_MOVE, 180);
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length+20, rand(height+4 - ud, height + ud), 5, 0.75);
		} else {
			SetMovePosition03(GetX - length-20, rand(height - ud, height + ud), 5, 0.75);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length-20, rand(height - ud, height + ud), 5, 0.75);
		} else {
			SetMovePosition03(GetX + length+20, rand(height - ud, height + ud), 5, 0.75);
		}
	}
}


sub ExMove3 { ExMove___(GetCenterY-120, 10, rand(60, 120)); }
function ExMove___(height, ud, length) {
PlaySE(poof);
	
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition02(GetX + length, rand(height+20 - ud, height + ud), 1);
		} else {
			SetMovePosition02(GetX - length, rand(height - ud, height + ud), 1);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition02(GetX - length, rand(height - ud, height + ud), 1);
		} else {
			SetMovePosition02(GetX + length, rand(height - ud, height + ud), 1);
		}
	}
}



function GetDistance(x1,y1,x2,y2){
return(((x2-x1)^2+(y2-y1)^2)^(1/2))
} 


 @DrawLoop {
SetGraphicAngle(0, 0, 0);
SetTexture(imageFile);
SetAlpha(alpha);
 SetGraphicScale(1,1);
DrawBoss(imageFile);
SetAlpha(255);


}


@Finalize {
if(GetCommonDataDefault("lastattack", false)==true){ PlaySE(die); }
loop(11-floor((GetMissCount+GetBombCount)/2)){
CreateItem(ITEM_SCORE, GetX+rand(-100, 100), GetY+rand(-45, 44));
}
}