script_enemy_main{

let effect1=0;
let object1=[];
let timer1=[];
let scale1=[];

let character="Amaya";
let cutin=character;
let dispelled=0;
let spellcards=3;
if(GetCommonData("Difficulty")==4){ spellcards=4; }
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 EFmoon=("\script\Shots\Biggest.png");
let SEspawn1=("\script\SoundEffects\spawn1.wav");
let SEshotm3=("\script\SoundEffects\shotm3.wav");

let GRboss=("\script\Images\CharacterSprites\Amaya.png");

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

@Initialize{
	LoadUserShotData("script\shots\ShotsAmaya1.txt");
	LoadGraphic(GRboss);

	LoadGraphic("\script\Shots\Biggest.png");
	LoadSE("\script\SoundEffects\spawn1.wav");
	LoadSE("\script\SoundEffects\shotm3.wav");

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

	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetCommonData("Boss1Vanish",1);

	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(64,64,64,64);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=4; }
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==0 && time>=60){
let angle=rand(0,360);
	loop(30){
	if(time%120==0){ CreateShot01((GetX+10)+20*cos(angle),(GetY-30)+20*sin(angle),2,angle+70,153,10); }
	if(time%120!=0){ CreateShot01((GetX+10)+20*cos(angle),(GetY-30)+20*sin(angle),2,angle-70,165,10); }
	angle+=360/30;
	}
usespell=60;
PlaySE(SEshotm3);
}

if((time+90)%180==0 && time>=60){
let angle=0;
if(time%360==0){ angle=90; }
if(time%360!=0){ angle=0; }
	angle+=360/10;
	loop(2){
		loop(5){
			loop(2){
			effect1=(Obj_Create(OBJ_EFFECT));
			Obj_SetPosition(effect1,GetX,GetY);
			ObjEffect_SetScale(effect1,0,0);
			Obj_SetSpeed(effect1,0); Obj_SetAngle(effect1,angle);
			ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,EFmoon); ObjEffect_SetRenderState(effect1,ALPHA);
			ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
			ObjEffect_SetVertexXY(effect1,0,-80,-80); ObjEffect_SetVertexUV(effect1,0,160,0);
			ObjEffect_SetVertexXY(effect1,1,80,-80); ObjEffect_SetVertexUV(effect1,1,319,0);
			ObjEffect_SetVertexXY(effect1,2,-80,80); ObjEffect_SetVertexUV(effect1,2,160,159);
			ObjEffect_SetVertexXY(effect1,3,80,80); ObjEffect_SetVertexUV(effect1,3,319,159);
			ObjEffect_SetVertexColor(effect1,0,255,255,255,230); ObjEffect_SetVertexColor(effect1,1,255,255,255,230);
			ObjEffect_SetVertexColor(effect1,2,255,255,255,230); ObjEffect_SetVertexColor(effect1,3,255,255,255,230);
			object1=object1~[effect1];
			timer1=timer1~[effect1];
			timer1[length(object1)-1]=0;
			scale1=scale1~[effect1];
			scale1[length(object1)-1]=0;
			}
		angle+=360/5;
		}
	angle+=360/10;
	}
PlaySE(SEspawn1);
usespell=-30;
}

let i=0;
while(i<length(object1)){
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); timer1=erase(timer1,i); scale1=erase(scale1,i);
	i--;
	}
	else{
	Obj_SetPosition(object1[i],Obj_GetX(object1[i])+Obj_GetSpeed(object1[i])*cos(Obj_GetAngle(object1[i])),Obj_GetY(object1[i])+Obj_GetSpeed(object1[i])*sin(Obj_GetAngle(object1[i])));
	ObjEffect_SetScale(object1[i],scale1[i],scale1[i]);
	ObjEffect_SetAngle(object1[i],0,0,timer1[i]*2);
	SetCollisionB(Obj_GetX(object1[i]),Obj_GetY(object1[i]),55*scale1[i]);

	if(scale1[i]<1){ scale1[i]=scale1[i]+0.1; }
	else{ Obj_SetSpeed(object1[i],1); }

	timer1[i]=timer1[i]+1;
	}
i++;
}

} // Easy

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

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

if(time%40==0 && time>=60){
let angle=rand(0,360);
	loop(50){
	if(time%80==0){ CreateShot01((GetX+10)+20*cos(angle),(GetY-30)+20*sin(angle),2,angle+70,153,10); }
	if(time%80!=0){ CreateShot01((GetX+10)+20*cos(angle),(GetY-30)+20*sin(angle),2,angle-70,165,10); }
	angle+=360/50;
	}
usespell=60;
PlaySE(SEshotm3);
}

if((time+90)%180==0 && time>=60){
let angle=0;
if(time%360==0){ angle=90; }
if(time%360!=0){ angle=0; }
	angle+=360/10;
	loop(2){
		loop(5){
			loop(2){
			effect1=(Obj_Create(OBJ_EFFECT));
			Obj_SetPosition(effect1,GetX,GetY);
			ObjEffect_SetScale(effect1,0,0);
			Obj_SetSpeed(effect1,0); Obj_SetAngle(effect1,angle);
			ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,EFmoon); ObjEffect_SetRenderState(effect1,ALPHA);
			ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
			ObjEffect_SetVertexXY(effect1,0,-80,-80); ObjEffect_SetVertexUV(effect1,0,160,0);
			ObjEffect_SetVertexXY(effect1,1,80,-80); ObjEffect_SetVertexUV(effect1,1,319,0);
			ObjEffect_SetVertexXY(effect1,2,-80,80); ObjEffect_SetVertexUV(effect1,2,160,159);
			ObjEffect_SetVertexXY(effect1,3,80,80); ObjEffect_SetVertexUV(effect1,3,319,159);
			ObjEffect_SetVertexColor(effect1,0,255,255,255,230); ObjEffect_SetVertexColor(effect1,1,255,255,255,230);
			ObjEffect_SetVertexColor(effect1,2,255,255,255,230); ObjEffect_SetVertexColor(effect1,3,255,255,255,230);
			object1=object1~[effect1];
			timer1=timer1~[effect1];
			timer1[length(object1)-1]=0;
			scale1=scale1~[effect1];
			scale1[length(object1)-1]=0;
			}
		angle+=360/5;
		}
	angle+=360/10;
	}
PlaySE(SEspawn1);
usespell=-30;
}

let i=0;
while(i<length(object1)){
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); timer1=erase(timer1,i); scale1=erase(scale1,i);
	i--;
	}
	else{
	Obj_SetPosition(object1[i],Obj_GetX(object1[i])+Obj_GetSpeed(object1[i])*cos(Obj_GetAngle(object1[i])),Obj_GetY(object1[i])+Obj_GetSpeed(object1[i])*sin(Obj_GetAngle(object1[i])));
	ObjEffect_SetScale(object1[i],scale1[i],scale1[i]);
	ObjEffect_SetAngle(object1[i],0,0,timer1[i]*2);
	SetCollisionB(Obj_GetX(object1[i]),Obj_GetY(object1[i]),55*scale1[i]);

	if(scale1[i]<1){ scale1[i]=scale1[i]+0.1; }
	else{ Obj_SetSpeed(object1[i],1); }

	timer1[i]=timer1[i]+1;
	}
i++;
}

} // Normal

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

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

if(time%30==0 && time>=60){
let angle=rand(0,360);
	loop(70){
	if(time%60==0){ CreateShot01((GetX+10)+20*cos(angle),(GetY-30)+20*sin(angle),3,angle+70,153,10); }
	if(time%60!=0){ CreateShot01((GetX+10)+20*cos(angle),(GetY-30)+20*sin(angle),3,angle-70,165,10); }
	angle+=360/70;
	}
usespell=60;
PlaySE(SEshotm3);
}

if(time%90==0 && time>=60){
let angle=0;
if(time%180==0){ angle=90; }
if(time%180!=0){ angle=0; }
	angle+=360/10;
	loop(2){
		loop(5){
			loop(2){
			effect1=(Obj_Create(OBJ_EFFECT));
			Obj_SetPosition(effect1,GetX,GetY);
			ObjEffect_SetScale(effect1,0,0);
			Obj_SetSpeed(effect1,0); Obj_SetAngle(effect1,angle);
			ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,EFmoon); ObjEffect_SetRenderState(effect1,ALPHA);
			ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
			ObjEffect_SetVertexXY(effect1,0,-80,-80); ObjEffect_SetVertexUV(effect1,0,160,0);
			ObjEffect_SetVertexXY(effect1,1,80,-80); ObjEffect_SetVertexUV(effect1,1,319,0);
			ObjEffect_SetVertexXY(effect1,2,-80,80); ObjEffect_SetVertexUV(effect1,2,160,159);
			ObjEffect_SetVertexXY(effect1,3,80,80); ObjEffect_SetVertexUV(effect1,3,319,159);
			ObjEffect_SetVertexColor(effect1,0,255,255,255,230); ObjEffect_SetVertexColor(effect1,1,255,255,255,230);
			ObjEffect_SetVertexColor(effect1,2,255,255,255,230); ObjEffect_SetVertexColor(effect1,3,255,255,255,230);
			object1=object1~[effect1];
			timer1=timer1~[effect1];
			timer1[length(object1)-1]=0;
			scale1=scale1~[effect1];
			scale1[length(object1)-1]=0;
			}
		angle+=360/5;
		}
	angle+=360/10;
	}
PlaySE(SEspawn1);
usespell=-30;
}

let i=0;
while(i<length(object1)){
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); timer1=erase(timer1,i); scale1=erase(scale1,i);
	i--;
	}
	else{
	Obj_SetPosition(object1[i],Obj_GetX(object1[i])+Obj_GetSpeed(object1[i])*cos(Obj_GetAngle(object1[i])),Obj_GetY(object1[i])+Obj_GetSpeed(object1[i])*sin(Obj_GetAngle(object1[i])));
	ObjEffect_SetScale(object1[i],scale1[i],scale1[i]);
	ObjEffect_SetAngle(object1[i],0,0,timer1[i]*2);
	SetCollisionB(Obj_GetX(object1[i]),Obj_GetY(object1[i]),55*scale1[i]);

	if(scale1[i]<1){ scale1[i]=scale1[i]+0.1; }
	else{ Obj_SetSpeed(object1[i],1.5); }

	timer1[i]=timer1[i]+1;
	}
i++;
}

} // Hard

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

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

if(time%20==0 && time>=60){
let angle=rand(0,360);
	loop(80){
	if(time%40==0){ CreateShot01((GetX+10)+20*cos(angle),(GetY-30)+20*sin(angle),3,angle+70,153,10); }
	if(time%40!=0){ CreateShot01((GetX+10)+20*cos(angle),(GetY-30)+20*sin(angle),3,angle-70,165,10); }
	angle+=360/80;
	}
usespell=60;
PlaySE(SEshotm3);
}

if(time%90==0 && time>=60){
let angle=0;
if(time%180==0){ angle=90; }
if(time%180!=0){ angle=0; }
	angle+=360/10;
	loop(2){
		loop(5){
			loop(2){
			effect1=(Obj_Create(OBJ_EFFECT));
			Obj_SetPosition(effect1,GetX,GetY);
			ObjEffect_SetScale(effect1,0,0);
			Obj_SetSpeed(effect1,0); Obj_SetAngle(effect1,angle);
			ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,EFmoon); ObjEffect_SetRenderState(effect1,ALPHA);
			ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
			ObjEffect_SetVertexXY(effect1,0,-80,-80); ObjEffect_SetVertexUV(effect1,0,160,0);
			ObjEffect_SetVertexXY(effect1,1,80,-80); ObjEffect_SetVertexUV(effect1,1,319,0);
			ObjEffect_SetVertexXY(effect1,2,-80,80); ObjEffect_SetVertexUV(effect1,2,160,159);
			ObjEffect_SetVertexXY(effect1,3,80,80); ObjEffect_SetVertexUV(effect1,3,319,159);
			ObjEffect_SetVertexColor(effect1,0,255,255,255,230); ObjEffect_SetVertexColor(effect1,1,255,255,255,230);
			ObjEffect_SetVertexColor(effect1,2,255,255,255,230); ObjEffect_SetVertexColor(effect1,3,255,255,255,230);
			object1=object1~[effect1];
			timer1=timer1~[effect1];
			timer1[length(object1)-1]=0;
			scale1=scale1~[effect1];
			scale1[length(object1)-1]=0;
			}
		angle+=360/5;
		}
	angle+=360/10;
	}
PlaySE(SEspawn1);
usespell=-30;
}

let i=0;
while(i<length(object1)){
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); timer1=erase(timer1,i); scale1=erase(scale1,i);
	i--;
	}
	else{
	Obj_SetPosition(object1[i],Obj_GetX(object1[i])+Obj_GetSpeed(object1[i])*cos(Obj_GetAngle(object1[i])),Obj_GetY(object1[i])+Obj_GetSpeed(object1[i])*sin(Obj_GetAngle(object1[i])));
	ObjEffect_SetScale(object1[i],scale1[i],scale1[i]);
	ObjEffect_SetAngle(object1[i],0,0,timer1[i]*2);
	SetCollisionB(Obj_GetX(object1[i]),Obj_GetY(object1[i]),55*scale1[i]);

	if(scale1[i]<1){ scale1[i]=scale1[i]+0.1; }
	else{ Obj_SetSpeed(object1[i],1.5); }

	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";

SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);
}

@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{
}

}