script_enemy_main{

let angle=rand(0,360);

let shot1=0;
let bullet1=[];
let timer1=[];
let angle1=[];

let character="Sayuri";
let cutin=character;
let dispelled=0;
let spellcards=2;
if(GetCommonData("Difficulty")>=3){ spellcards=3; }
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let frame=0; let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshots5=("script\SoundEffects\shots5.wav");
let SEshots6=("script\SoundEffects\shots6.wav");
let GRboss=("\script\Images\CharacterSprites\Sayuri.png");

#include_function "script/Functions/HealthBarLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsSayuri1.txt");

	LoadSE("script\SoundEffects\shots5.wav");
	LoadSE("script\SoundEffects\shots6.wav");
	LoadGraphic("\script\Images\CharacterSprites\Sayuri.png");

	SetLife(250);
	SetTimer(30);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);

	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));

	SetCommonData("Boss2Move",4);
	
	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{
SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,32,32,4);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=5; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

HealthBar();

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}


if(GetCommonData("Difficulty")==1){

if(time>=60 && time%8==0){
let angle=time*1.26;
	loop(3){
	let shot1=0;
	let delay=0;
	let radius=40+20*cos(time+180);
	CreateShotA(shot1,GetX+radius*cos(-angle),GetY+radius*sin(-angle),10);
	SetShotDataA(shot1,0,1.2,-angle,0,0,0,74);
		loop(8){
		SetShotDataA(shot1,delay,NULL,NULL,0,0.02,1.2,74);
		SetShotDataA(shot1,45+delay,NULL,NULL,0,-0.02,0.6,86);
		delay+=90;
		}
	FireShot(shot1);
	angle+=360/3;
	}
PlaySE(SEshots6);
}

if((time+140)%240==0 && time>=60){
let angle=rand(0,360);
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,1.6);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,80);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/3;
	}
}
if(time%5==0 && time>=60){ PlaySE(SEshots5); }

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	if(timer1[i]<25){ angle1[i]=angle1[i]+4; }
	let wave=0;
		loop(3){
		if(timer1[i]>=25+wave && timer1[i]<75+wave){ angle1[i]=angle1[i]-2; }
		if(timer1[i]>=75+wave && timer1[i]<125+wave){ angle1[i]=angle1[i]+2; }
		wave+=100;
		}
	
	Obj_SetAngle(bullet1[i],angle1[i]);
	
	if(time%6==0){
		let shotx=0;
		CreateShotA(shotx,Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),15);
		SetShotDataA(shotx,0,0,angle1[i]-timer1[i]*7,0,0.012,1.5,81);
		FireShot(shotx);
	}
	
	if(timer1[i]>=400){ ObjShot_FadeDelete(bullet1[i]); }
	timer1[i]=timer1[i]+1;
	}
i++;
}

} //Easy

//=============================================================================================================

if(GetCommonData("Difficulty")==2){

if(time>=60 && time%8==0){
let angle=time*1.46;
	loop(3){
	let shot1=0;
	let delay=0;
	let radius=40+20*cos(time+180);
	CreateShotA(shot1,GetX+radius*cos(-angle),GetY+radius*sin(-angle),10);
	SetShotDataA(shot1,0,1.2,-angle,0,0,0,74);
		loop(8){
		SetShotDataA(shot1,delay,NULL,NULL,0,0.02,1.2,74);
		SetShotDataA(shot1,45+delay,NULL,NULL,0,-0.02,0.6,86);
		delay+=90;
		}
	FireShot(shot1);
	angle+=360/3;
	}
PlaySE(SEshots6);
}

if((time+140)%240==0 && time>=60){
let angle=rand(0,360);
	loop(4){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,2);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,80);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/4;
	}
}
if(time%5==0 && time>=60){ PlaySE(SEshots5); }

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	if(timer1[i]<25){ angle1[i]=angle1[i]+4; }
	let wave=0;
		loop(3){
		if(timer1[i]>=25+wave && timer1[i]<75+wave){ angle1[i]=angle1[i]-2; }
		if(timer1[i]>=75+wave && timer1[i]<125+wave){ angle1[i]=angle1[i]+2; }
		wave+=100;
		}
	
	Obj_SetAngle(bullet1[i],angle1[i]);
	
	if(time%6==0){
		let shotx=0;
		CreateShotA(shotx,Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),15);
		SetShotDataA(shotx,0,0,angle1[i]-timer1[i]*7,0,0.015,1.8,81);
		FireShot(shotx);
	}
	
	if(timer1[i]>=400){ ObjShot_FadeDelete(bullet1[i]); }
	timer1[i]=timer1[i]+1;
	}
i++;
}

} //Normal

//=============================================================================================================

if(GetCommonData("Difficulty")==3){

if(time>=60 && time%6==0){
let angle=time*1.56;
	loop(4){
	let shot1=0;
	let delay=0;
	let radius=40+20*cos(time+180);
	CreateShotA(shot1,GetX+radius*cos(-angle),GetY+radius*sin(-angle),10);
	SetShotDataA(shot1,0,1.2,-angle,0,0,0,74);
		loop(8){
		SetShotDataA(shot1,delay,NULL,NULL,0,0.02,1.2,74);
		SetShotDataA(shot1,45+delay,NULL,NULL,0,-0.02,0.6,86);
		delay+=90;
		}
	FireShot(shot1);
	angle+=360/4;
	}
PlaySE(SEshots6);
}

if((time+140)%240==0 && time>=60){
let angle=rand(0,360);
	loop(5){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,2);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,80);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/5;
	}
}
if(time%5==0 && time>=60){ PlaySE(SEshots5); }

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	if(timer1[i]<25){ angle1[i]=angle1[i]+4; }
	let wave=0;
		loop(3){
		if(timer1[i]>=25+wave && timer1[i]<75+wave){ angle1[i]=angle1[i]-2; }
		if(timer1[i]>=75+wave && timer1[i]<125+wave){ angle1[i]=angle1[i]+2; }
		wave+=100;
		}
	
	Obj_SetAngle(bullet1[i],angle1[i]);
	
	if(time%5==0){
		let shotx=0;
		CreateShotA(shotx,Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),15);
		SetShotDataA(shotx,0,0,angle1[i]-timer1[i]*7,0,0.015,2,81);
		FireShot(shotx);
	}
	
	if(timer1[i]>=400){ ObjShot_FadeDelete(bullet1[i]); }
	timer1[i]=timer1[i]+1;
	}
i++;
}

} //Hard

//=============================================================================================================

if(GetCommonData("Difficulty")==4){

if(time>=60 && time%5==0){
let angle=time*1.66;
	loop(4){
	let shot1=0;
	let delay=0;
	let radius=40+20*cos(time+180);
	CreateShotA(shot1,GetX+radius*cos(-angle),GetY+radius*sin(-angle),10);
	SetShotDataA(shot1,0,1.2,-angle,0,0,0,74);
		loop(8){
		SetShotDataA(shot1,delay,NULL,NULL,0,0.02,1.2,74);
		SetShotDataA(shot1,45+delay,NULL,NULL,0,-0.02,0.6,86);
		delay+=90;
		}
	FireShot(shot1);
	angle+=360/4;
	}
PlaySE(SEshots6);
}

if((time+100)%200==0 && time>=60){
let angle=rand(0,360);
	loop(5){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,3);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,80);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/5;
	}
}
if(time%5==0 && time>=60){ PlaySE(SEshots5); }

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	if(timer1[i]<25){ angle1[i]=angle1[i]+4; }
	let wave=0;
		loop(3){
		if(timer1[i]>=25+wave && timer1[i]<75+wave){ angle1[i]=angle1[i]-2; }
		if(timer1[i]>=75+wave && timer1[i]<125+wave){ angle1[i]=angle1[i]+2; }
		wave+=100;
		}
	
	Obj_SetAngle(bullet1[i],angle1[i]);
	
	if(time%5==0){
		let shotx=0;
		CreateShotA(shotx,Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),15);
		SetShotDataA(shotx,0,0,angle1[i]-timer1[i]*7,0,0.015,2,81);
		FireShot(shotx);
	}
	
	if(timer1[i]>=400){ ObjShot_FadeDelete(bullet1[i]); }
	timer1[i]=timer1[i]+1;
	}
i++;
}

} //Lunatic


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/HealthBar.txt";
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }

	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}
 
@Finalize{
}

}