script_enemy_main{

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

let frame2=0;
let angle1=180;

let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let frame=-90;
let time=-90;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let GRboss=("\script\Images\CharacterSprites\Mai.png");

let SEshotm1=("\script\SoundEffects\shotm1.wav");
let SEshots6=("\script\SoundEffects\shots6.wav");

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

	SetLife(10000);
	SetColor(130,130,0);
	Concentration01(90);
	SetColor(255,255,255);
	SetX(GetCommonData("Boss2X"));
	SetY(GetCommonData("Boss2Y"));
	SetMovePosition02(cx+100,miny+120,50);
}
	
@MainLoop{

SetCollisionB(GetX,GetY,16);
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=10; }
SetDamageRate(damagerate,damagerate);

if(time%20==0){ SetMovePosition02(cx+100*cos(time+180),miny+100+40*sin(time+180),50); }


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

if(frame>=25 && frame<=75 && frame%25==0 && time>=75){
let angle=time+rand(-5,5);
	loop(40){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,3.5);
	ObjShot_SetDelay(shot1,30);
	ObjShot_SetGraphic(shot1,40);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	alpha1=alpha1~[shot1];
	alpha1[length(bullet1)-1]=0;
	angle+=360/40;
	}
PlaySE(SEshotm1);
}

if(time>=60){
let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); timer1=erase(timer1,i); alpha1=erase(alpha1,i);
		i--;
		}
		else{
		Obj_SetAlpha(bullet1[i],alpha1[i]);
		if(alpha1[i]<255 && timer1[i]>50){ alpha1[i]=alpha1[i]+3; }
		timer1[i]=timer1[i]+1;
		}
	i++;
	}
}

if(frame==150){ frame=0; }

if(frame2>=180 && frame2<300 && time%3==0 && time>=60){
let shot1=0;
let direction=-30;
	loop(3){
	CreateShotA(shot1,GetX-10,GetY-20,0);
	SetShotDataA(shot1,0,3.5,angle1,0,-0.1,0,96);
	SetShotDirectionType(PLAYER);
	SetShotDataA(shot1,120,0,direction,0,0.1,5,96);
	SetShotDirectionType(ABSOLUTE);
	FireShot(shot1);
	direction+=30;
	}
angle1+=360/40;
usespell=5;
PlaySE(SEshots6);
}

if(frame2==300){ frame2=0; }

} // Hard

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

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

if(frame>=30 && frame<75 && frame%15==0 && time>=75){
let angle=time+rand(-5,5);
	loop(50){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,3.5);
	ObjShot_SetDelay(shot1,30);
	ObjShot_SetGraphic(shot1,40);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	alpha1=alpha1~[shot1];
	alpha1[length(bullet1)-1]=0;
	angle+=360/50;
	}
PlaySE(SEshotm1);
}

if(time>=60){
let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); timer1=erase(timer1,i); alpha1=erase(alpha1,i);
		i--;
		}
		else{
		Obj_SetAlpha(bullet1[i],alpha1[i]);
		if(alpha1[i]<255 && timer1[i]>65){ alpha1[i]=alpha1[i]+4; }
		timer1[i]=timer1[i]+1;
		}
	i++;
	}
}

if(frame==120){ frame=0; }

if(frame2>=180 && frame2<300 && time%3==0 && time>=60){
let shot1=0;
let direction=-20;
	loop(3){
	CreateShotA(shot1,GetX-10,GetY-20,0);
	SetShotDataA(shot1,0,5,angle1,0,-0.1,0,96);
	SetShotDirectionType(PLAYER);
	SetShotDataA(shot1,120,0,direction,0,0.1,5,96);
	SetShotDirectionType(ABSOLUTE);
	FireShot(shot1);
	direction+=20;
	}
angle1+=360/40;
usespell=5;
PlaySE(SEshots6);
}


if(frame2==300){ frame2=0; }

} //Lunatic


time++;
frame++;
frame2++;

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(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); }
	}
	DrawGraphic(GetX,GetY);
}

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