script_enemy_main{

let count=0;
let size=6;
let timebetween=0;
let phase=0;

let xpos=GetClipMinX+30;
let ypos=0;

let shot1=0;
let bullet1=[];
let radius1=[];
let accel1=[];
let movetime1=[];
let movecounter1=[];
let sound1=[];
let xpos1=[];
let ypos1=[];

let SEshotm1=("script\SoundEffects\shotm1.wav");
let SEshotm2=("script\SoundEffects\shotm2.wav");
let SEshotb1=("script\SoundEffects\shotb1.wav");
let SEshotb2=("script\SoundEffects\shotb2.wav");
let SEshotb6=("script\SoundEffects\shotb6.wav");

let SExylo1=("script\SoundEffects\xylo1.wav");
let SExylo2=("script\SoundEffects\xylo2.wav");
let SExylo3=("script\SoundEffects\xylo3.wav");
let SExylo4=("script\SoundEffects\xylo4.wav");
let SExylo5=("script\SoundEffects\xylo5.wav");

let character="Mai";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=78;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=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 BG1=("\script\Images\BackgroundLayers\Mai3.png");
let BG2=("\script\Images\BackgroundLayers\Mai2.png");
let GRboss=("\script\Images\CharacterSprites\"~character~".png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\Shots"~character~"1.txt");
	
	LoadSE("script\SoundEffects\shotm1.wav");
	LoadSE("script\SoundEffects\shotm2.wav");
	LoadSE("script\SoundEffects\shotb1.wav");
	LoadSE("script\SoundEffects\shotb2.wav");
	LoadSE("script\SoundEffects\shotb6.wav");

	LoadSE("script\SoundEffects\xylo1.wav");
	LoadSE("script\SoundEffects\xylo2.wav");
	LoadSE("script\SoundEffects\xylo3.wav");
	LoadSE("script\SoundEffects\xylo4.wav");
	LoadSE("script\SoundEffects\xylo5.wav");
	
	LoadGraphic("\script\Images\CharacterSprites\"~character~".png");
	LoadGraphic("\script\Images\BackgroundLayers\Mai3.png");
	LoadGraphic("\script\Images\BackgroundLayers\Mai2.png");

	SetScore(2500000);
	SetLife(600);
	SetTimer(76);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+180,50);
}
	
@MainLoop{

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

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

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Virtuoso [Musical Score]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

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


if(time==60){
let shotx=0;
let pos=miny+40;
	loop(5){	
	shotx=(Obj_Create(OBJ_LASER));
	Obj_SetPosition(shotx,minx+15,pos);
	Obj_SetAngle(shotx,0);
	ObjLaser_SetLength(shotx,(maxx-15)-(minx+15));
	ObjLaser_SetWidth(shotx,10);
	ObjShot_SetDelay(shotx,10000);
	ObjLaser_SetSource(shotx,false);
	ObjShot_SetGraphic(shotx,97);
	pos+=20;
	}
pos=cy-40;
	loop(5){	
	shotx=(Obj_Create(OBJ_LASER));
	Obj_SetPosition(shotx,minx+15,pos);
	Obj_SetAngle(shotx,0);
	ObjLaser_SetLength(shotx,(maxx-15)-(minx+15));
	ObjLaser_SetWidth(shotx,10);
	ObjShot_SetDelay(shotx,10000);
	ObjLaser_SetSource(shotx,false);
	ObjShot_SetGraphic(shotx,101);
	pos+=20;
	}
pos=maxy-40;
	loop(5){	
	shotx=(Obj_Create(OBJ_LASER));
	Obj_SetPosition(shotx,minx+15,pos);
	Obj_SetAngle(shotx,0);
	ObjLaser_SetLength(shotx,(maxx-15)-(minx+15));
	ObjLaser_SetWidth(shotx,10);
	ObjShot_SetDelay(shotx,10000);
	ObjLaser_SetSource(shotx,false);
	ObjShot_SetGraphic(shotx,104);
	pos-=20;
	}
}


if(time%(30-timebetween)==0 && count<size && frame>=120){
let sound=rand_int(1,5);
if((phase+0)%3==0){ ypos=miny+20+(20*sound); }
if((phase+1)%3==0){ ypos=maxy-140+(20*sound); }
if((phase+2)%3==0){ ypos=cy-60+(20*sound); }
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX-10,GetY-20);
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,180);
	Obj_SetCollisionToPlayer(shot1,false);
	bullet1=bullet1~[shot1];
	radius1=radius1~[shot1];
	radius1[length(bullet1)-1]=0;
	accel1=accel1~[shot1];
	accel1[length(bullet1)-1]=0;
	movetime1=movetime1~[shot1];
	movetime1[length(bullet1)-1]=0;
	movecounter1=movecounter1~[shot1];
	movecounter1[length(bullet1)-1]=0;
	sound1=sound1~[shot1];
	sound1[length(bullet1)-1]=sound;
	xpos1=xpos1~[shot1];
	xpos1[length(bullet1)-1]=xpos;
	ypos1=ypos1~[shot1];
	ypos1[length(bullet1)-1]=ypos;
xpos+=((maxx-30)-(minx+30))/(size-1);
count++;
usespell=35;
}


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); radius1=erase(radius1,i); accel1=erase(accel1,i); xpos1=erase(xpos1,i); ypos1=erase(ypos1,i);
	movetime1=erase(movetime1,i); movecounter1=erase(movecounter1,i); sound1=erase(sound1,i);
	i--;
	}
	else{
	if(movecounter1[i]==0){
		movetime1[i]=90;
		radius1[i]=(((xpos1[i]-Obj_GetX(bullet1[i]))^2+(ypos1[i]-Obj_GetY(bullet1[i]))^2)^0.5)/movetime1[i]*(pi/2);
		Obj_SetAngle(bullet1[i],atan2(ypos1[i]-Obj_GetY(bullet1[i]),xpos1[i]-Obj_GetX(bullet1[i])));
	}
	if(movecounter1[i]<movetime1[i]){
		accel1[i]=accel1[i]+180/movetime1[i];
		Obj_SetSpeed(bullet1[i],radius1[i]*sin(accel1[i]));
	}
	movecounter1[i]=movecounter1[i]+1;
	
	if(movecounter1[i]==movetime1[i]){
		if(sound1[i]==1){ PlaySE(SExylo1); }
		if(sound1[i]==2){ PlaySE(SExylo2); }
		if(sound1[i]==3){ PlaySE(SExylo3); }
		if(sound1[i]==4){ PlaySE(SExylo4); }
		if(sound1[i]==5){ PlaySE(SExylo5); }
	}

	if(movecounter1[i]==movetime1[i]+90){
	
		if(sound1[i]==1){
		let angle1=atan2(GetPlayerY-Obj_GetY(bullet1[i]),GetPlayerX-Obj_GetX(bullet1[i]));
			loop(15){
			let angle2=rand(0,360);
			SetShotColor(220,220,220);
				loop(10){
				CreateShot01(Obj_GetX(bullet1[i])+25*cos(angle2),Obj_GetY(bullet1[i])+25*sin(angle2),3,angle1,67,10);
				angle2+=360/10;
				}
			SetShotColor(255,255,255);
			angle1+=360/15;
			}
		PlaySE(SEshotm2);
		}
	
		if(sound1[i]==2){
		let angle=atan2(GetPlayerY-Obj_GetY(bullet1[i]),GetPlayerX-Obj_GetX(bullet1[i]));
			loop(25){
			let speed=4;
			SetShotColor(170,170,150);
				loop(7){
				CreateShot01(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),speed,angle,50,10);
				speed-=0.4;
				}
			SetShotColor(255,255,255);
			angle+=360/25;
			}
		PlaySE(SEshotm1);
		}
		
		if(sound1[i]==3){
		let angle=rand(0,360);
		let shotx=0;
		let delay2=0;
			loop(10){
				loop(10){
				SetShotColor(210,195,175);
				CreateShotA(shotx,Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),delay2);
				SetShotDataA(shotx,0,3,angle,7,0,0,180);
				let delay1=0;
					loop(6){
					SetShotDataA(shotx,8+delay1,NULL,NULL,-7,0,0,180);
					SetShotDataA(shotx,24+delay1,NULL,NULL,7,0,0,180);
					delay1+=32;
					}
				SetShotDataA(shotx,8+delay1,NULL,NULL,0,0,0,180);					
				FireShot(shotx);
				SetShotColor(255,255,255);
				angle+=360/10;
				}
			delay2+=3;
			}
		PlaySE(SEshotb6);
		}

		if(sound1[i]==4){
		let shot1=0;
		let angle=rand(0,360);
		SetShotColor(220,220,220);
			loop(90){
			CreateShot01(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),rand(1.5,4),angle,89,10);
			angle+=360/90;
			}
		SetShotColor(255,255,255);
		PlaySE(SEshotb1);
		}

		if(sound1[i]==5){
		let angle1=0;
			loop(16){
			let angle2=-4;
				loop(5){
				SetShotDirectionType(PLAYER);
				SetShotColor(210,195,175);
				CreateShot01(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),3,angle1+angle2,192,10);
				SetShotColor(255,255,255);
				SetShotDirectionType(ABSOLUTE);
				angle2+=2;
				}
			angle1+=360/16;
			}
		PlaySE(SEshotb2);
		}

	movecounter1[i]=0;
	Obj_Delete(bullet1[i]);
	}

	}
i++;
}

if(count==size){
	xpos=GetClipMinX+30;
	count=0;
	size++;
	frame=0;
	phase++;
	if(timebetween<10){ timebetween++; }
}


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

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0-time,300,300-time);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetColor(180,180,180);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0,0,300,300);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(120,120,120);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
}

@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{
	if(GotSpellCardBonus){ SetCommonData("LastTrumpCard",11); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}