script_enemy_main{

let charge=0;
let oldx=0;
let newx=0;
let movedir=0;
let effect1=0;
let object1=[];
let timer1=[];

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 SEshotb5=("\script\SoundEffects\shotb5.wav");
let SEmagics5=("\script\SoundEffects\magics5.wav");

let GRfade=("\script\Images\OtherEffects\MaiAdd.png");
let GRboss=("\script\Images\CharacterSprites\Mai.png");

@Initialize{
	LoadGraphic("\script\Images\OtherEffects\MaiAdd.png");
	LoadGraphic("\script\Images\CharacterSprites\Mai.png");

	LoadSE("\script\SoundEffects\shots5.wav");
	LoadSE("\script\SoundEffects\shotb5.wav");
	LoadSE("\script\SoundEffects\magics5.wav");

	SetLife(10000);
	MagicCircle(false);
	
	SetX(GetCommonData("Boss2X"));
	SetY(GetCommonData("Boss2Y"));
	SetMovePosition02(cx+100,cy-100,60);
}
	
@MainLoop{

SetCollisionB(GetX,GetY,16);

if(time==60){ SetAngle(GetCommonData("Angle")+90); }


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

if(time>=60){
SetSpeed(GetCommonData("Speed"));
	if(GetX<=minx){
	SetAngle(180-GetAngle);
	SetX(GetX+GetCommonData("Speed"));
		loop(2){
		let angle=0+rand(-80,80);
		CreateShot12(GetX,GetY,1.5*cos(angle),rand(-1,-2),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1,2),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetX>=maxx){
	SetAngle(180-GetAngle);
	SetX(GetX-GetCommonData("Speed"));
		loop(2){
		let angle=180+rand(-80,80);
		CreateShot12(GetX,GetY,1.5*cos(angle),rand(-1,-2),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1,2),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY<=miny){
	SetAngle(-GetAngle);
	SetY(GetY+GetCommonData("Speed"));
		loop(2){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,1.5*cos(angle),rand(0,-1),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1,2),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY>=maxy){
	SetAngle(-GetAngle);
	SetY(GetY-GetCommonData("Speed"));
		loop(2){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,1.5*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1,2),64,0);
		}
	PlaySE(SEmagics5);
	}
}

if((time+105)%210==0 && time>=180){
let shot1=0;
let angle=GetAngleToPlayer;
let speed=1.5;
let color=0;
	loop(2){
		loop(5){
		CreateShotA(shot1,GetX-10,GetY-20,20);
		SetShotDataA(shot1,0,speed,angle,0,-0.02,0,color+76);
		SetShotDataA(shot1,60,0,angle,0,0.075,2,color+76);
		FireShot(shot1);
		angle+=360/5;
		}
	angle+=360/10;
	speed-=0.5;
	color+=1;
	}
usespell=25;
PlaySE(SEshotb5);
}
if((time+40)%210==0 && time>=250){ PlaySE(SEshots5); }

} //Easy

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


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

if(time>=60){
SetSpeed(GetCommonData("Speed"));
	if(GetX<=minx){
	SetAngle(180-GetAngle);
	SetX(GetX+GetCommonData("Speed"));
		loop(3){
		let angle=0+rand(-80,80);
		CreateShot12(GetX,GetY,1.5*cos(angle),rand(-1,-2),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1,2),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetX>=maxx){
	SetAngle(180-GetAngle);
	SetX(GetX-GetCommonData("Speed"));
		loop(3){
		let angle=180+rand(-80,80);
		CreateShot12(GetX,GetY,1.5*cos(angle),rand(-1,-2),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1,2),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY<=miny){
	SetAngle(-GetAngle);
	SetY(GetY+GetCommonData("Speed"));
		loop(3){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,1.5*cos(angle),rand(0,-1),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1,2),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY>=maxy){
	SetAngle(-GetAngle);
	SetY(GetY-GetCommonData("Speed"));
		loop(3){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,1.5*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1,2),64,0);
		}
	PlaySE(SEmagics5);
	}
}

if((time+90)%180==0 && time>=180){
let shot1=0;
let angle=GetAngleToPlayer;
let speed=1.5;
let color=0;
	loop(2){
		loop(8){
		CreateShotA(shot1,GetX-10,GetY-20,20);
		SetShotDataA(shot1,0,speed,angle,0,-0.02,0,color+76);
		SetShotDataA(shot1,60,0,angle,0,0.075,2.5,color+76);
		FireShot(shot1);
		angle+=360/8;
		}
	angle+=360/16;
	speed-=0.5;
	color+=1;
	}
usespell=25;
PlaySE(SEshotb5);
}
if((time+10)%180==0 && time>=220){ PlaySE(SEshots5); }

} //Normal

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

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

if(time>=60){
SetSpeed(GetCommonData("Speed"));
	if(GetX<=minx){
	SetAngle(180-GetAngle);
	SetX(GetX+GetCommonData("Speed"));
		loop(4){
		let angle=0+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetX>=maxx){
	SetAngle(180-GetAngle);
	SetX(GetX-GetCommonData("Speed"));
		loop(4){
		let angle=180+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY<=miny){
	SetAngle(-GetAngle);
	SetY(GetY+GetCommonData("Speed"));
		loop(4){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(0,-1),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY>=maxy){
	SetAngle(-GetAngle);
	SetY(GetY-GetCommonData("Speed"));
		loop(4){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),64,0);
		}
	PlaySE(SEmagics5);
	}
}

if((time+75)%150==0 && time>=180){
let shot1=0;
let angle=GetAngleToPlayer;
let speed=1.5;
let color=0;
	loop(3){
		loop(10){
		CreateShotA(shot1,GetX-10,GetY-20,20);
		SetShotDataA(shot1,0,speed,angle,0,-0.02,0,color+76);
		SetShotDataA(shot1,60,0,angle,0,0.075,3,color+76);
		FireShot(shot1);
		angle+=360/10;
		}
	angle+=360/20;
	speed-=0.5;
	color+=1;
	}
usespell=25;
PlaySE(SEshotb5);
}
if(time%150==0 && time>=170){ PlaySE(SEshots5); }

} //Hard

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

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

if(time>=60){
SetSpeed(GetCommonData("Speed"));
	if(GetX<=minx){
	SetAngle(180-GetAngle);
	SetX(GetX+GetCommonData("Speed"));
		loop(5){
		let angle=0+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.5,2.5),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetX>=maxx){
	SetAngle(180-GetAngle);
	SetX(GetX-GetCommonData("Speed"));
		loop(5){
		let angle=180+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.5,2.5),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY<=miny){
	SetAngle(-GetAngle);
	SetY(GetY+GetCommonData("Speed"));
		loop(5){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(0,-1),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.5,2.5),64,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY>=maxy){
	SetAngle(-GetAngle);
	SetY(GetY-GetCommonData("Speed"));
		loop(5){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.5,2.5),64,0);
		}
	PlaySE(SEmagics5);
	}
}

if((time+60)%120==0 && time>=180){
let shot1=0;
let angle=GetAngleToPlayer;
let speed=1.5;
let color=0;
	loop(3){
		loop(15){
		CreateShotA(shot1,GetX-10,GetY-20,20);
		SetShotDataA(shot1,0,speed,angle,0,-0.02,0,color+76);
		SetShotDataA(shot1,60,0,angle,0,0.1,4,color+76);
		FireShot(shot1);
		angle+=360/15;
		}
	speed-=0.5;
	color+=1;
	}
usespell=25;
PlaySE(SEshotb5);
}
if((time-20)%120==0 && time>=160){ PlaySE(SEshots5); }

} //Lunatic


newx=GetX;
if(newx<oldx){ movedir=1; }
if(newx>oldx){ movedir=2; }
oldx=GetX;

if(GetCommonData("Speed")>=3.6 && charge==0){
	SetColor(130,130,0);
	Concentration01(90);
	SetColor(255,255,255);
	charge=1;
}

if(time%3==0 && GetCommonData("Speed")>=4){
let xsize=128;
let ysize=128;
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetX,GetY);
	ObjEffect_SetLayer(effect1,1);
	ObjEffect_SetTexture(effect1,GRfade);
	ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(effect1,4);
	if(usespell>=1){
	ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,384,0);
	ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,384+xsize,0);
	ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,384,ysize);
	ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,384+xsize,ysize);
	}
	if(usespell==0){
		if(movedir==1){
		ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,128,0);
		ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,128+xsize,0);
		ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,128,ysize);
		ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,128+xsize,ysize);
		}
		if(movedir==2){
		ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,256,0);
		ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,256+xsize,0);
		ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,256,ysize);
		ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,256+xsize,ysize);
		}
	}
	ObjEffect_SetVertexColor(effect1,0,80,255,255,255); ObjEffect_SetVertexColor(effect1,1,80,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,80,255,255,255); ObjEffect_SetVertexColor(effect1,3,80,255,255,255);
	object1=object1~[effect1];
	timer1=timer1~[effect1];
}

if(time==0){ loop(1500){ timer1=timer1~[effect1]; } }

if(GetCommonData("Speed")>=4){
let i=0;
	while (i<length(object1)){
		timer1[i]=timer1[i]+1;
		ObjEffect_SetVertexColor(object1[i],0,80-(timer1[i]*4),255,255,255); ObjEffect_SetVertexColor(object1[i],1,80-(timer1[i]*4),255,255,255);
		ObjEffect_SetVertexColor(object1[i],2,80-(timer1[i]*4),255,255,255); ObjEffect_SetVertexColor(object1[i],3,80-(timer1[i]*4),255,255,255);
			if(timer1[i]>=12){
			Obj_Delete(object1[i]);
			object1=erase(object1,i); timer1=erase(timer1,i); i--;
			}
	i++;
	}
}

time++;
frame++;

if(GetCommonData("UseSpell2")>0){ usespell=GetCommonData("UseSpell2"); SetCommonData("UseSpell2",0); }
if(usespell>0){ usespell--; }
if(usespell<0){ usespell++; }

SetCommonData("Boss2X",GetX); SetCommonData("Boss2Y",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(movedir==0){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(movedir==1){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(movedir==2){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}

@Finalize{
	if(GetCommonData("Difficulty")<3){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,"Mai"); }
}

}