script_enemy_main{

let absorb=0;
let moonsize=1;
let xpos=0;
let ypos=0;
let radius=60;
let size=0;
let shottype=0;
let bursttime=0;

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

let effect2=0;
let object2=[];
let timer2=[];
let scale2=[];
let moonsize2=[];

let shot2=0;
let bullet2=[];
let timer2=[];
let bounce2=[];
let reflect2=[];

let character="Amaya";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=76;
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 EFmoon=("\script\Shots\Biggest.png");
let SEspawn1=("\script\SoundEffects\spawn1.wav");
let SEshotm3=("\script\SoundEffects\shotm3.wav");
let SEshots7=("\script\SoundEffects\shots7.wav");

let BG1=("\script\Images\BackgroundLayers\Amaya4.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");

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

	LoadGraphic("\script\Images\CharacterSprites\"~character~".png");
	LoadGraphic("\script\Images\BackgroundLayers\Amaya4.png");

	SetScore(2500000);
	SetLife(300);
	SetTimer(80);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+80,50);

	SetCommonData("ResetAbsorb",0);
}
	
@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("PlayerType")==2){ damagerate=5; } }
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("Tsukuyomi No Mikoto [Yata No Kagami]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

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


if(time==90){
CreateEnemyFromFile(GetCurrentScriptDirectory~"Amaya - Yata No Kagami - Familiar.txt",GetX,GetY,0,0,0);

let angle=90;
	loop(8){
	shot1=(Obj_Create(OBJ_LASER));
	Obj_SetPosition(shot1,xpos+radius*cos(angle),ypos+radius*sin(angle));
	Obj_SetAngle(shot1,angle+90+(360/16));
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,194);
	ObjLaser_SetLength(shot1,100);
	ObjLaser_SetWidth(shot1,10);
	ObjLaser_SetSource(shot1,false);
	Obj_SetCollisionToObject(shot1,true);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	size1=size1~[shot1];
	size1[length(bullet1)-1]=1;
	angle+=360/8;
	}
}

xpos=(GetCommonDataDefault("EnemyX",GetX));
ypos=(GetCommonDataDefault("EnemyY",GetY));

radius=(size*60)+(GetCommonData("Absorb")/5);
if(size<1 && time>=90){ size+=0.01; }


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i); size1=erase(size1,i);
	i--;
	}
	else{
	size1[i]=radius/128;
	angle1[i]=angle1[i]+0.7+0.3*cos(time);
	
	if(bursttime>0){ ObjLaser_SetWidth(bullet1[i],3); }
	else{ ObjLaser_SetWidth(bullet1[i],10); }

	Obj_SetAngle(bullet1[i],angle1[i]);
	Obj_SetPosition(bullet1[i],xpos+radius*cos(angle1[i]+90+(360/16)),ypos+radius*sin(angle1[i]+90+(360/16)));
	ObjLaser_SetLength(bullet1[i],100*size1[i]);

	timer1[i]=timer1[i]+1;
	}
i++;
}
if(bursttime>0){ bursttime--; }

if(time%14==0 && time>=210){
let angle=time;
	loop(5){
	shot2=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot2,GetX,GetY);
	Obj_SetAngle(shot2,angle);
	Obj_SetSpeed(shot2,2.5);
	ObjShot_SetGraphic(shot2,35);
	ObjShot_SetDelay(shot2,15);
	bullet2=bullet2~[shot2];
	timer2=timer2~[shot2];
	timer2[length(bullet2)-1]=0;
	bounce2=bounce2~[shot2];
	bounce2[length(bullet2)-1]=0;
	reflect2=reflect2~[shot2];
	reflect2[length(bullet2)-1]=0;
	angle+=360/5;
	}
	loop(5){
	shot2=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot2,GetX,GetY);
	Obj_SetAngle(shot2,-angle*0.9);
	Obj_SetSpeed(shot2,2.5);
	ObjShot_SetGraphic(shot2,35);
	ObjShot_SetDelay(shot2,15);
	bullet2=bullet2~[shot2];
	timer2=timer2~[shot2];
	timer2[length(bullet2)-1]=0;
	bounce2=bounce2~[shot2];
	bounce2[length(bullet2)-1]=0;
	reflect2=reflect2~[shot2];
	reflect2[length(bullet2)-1]=0;
	angle+=360/5;
	}
PlaySE(SEshots7);
}


let i=0;
while(i<length(bullet2)){
	if(Obj_BeDeleted(bullet2[i])){
	bullet2=erase(bullet2,i); timer2=erase(timer2,i); bounce2=erase(bounce2,i); reflect2=erase(reflect2,i);
	i--;
	}
	else{
		let h=0;
		while(h<length(bullet1)){
			if(Collision_Obj_Obj(bullet2[i],bullet1[h])==true && reflect2[i]==0){
			SetCommonData("Absorb",GetCommonDataDefault("Absorb",0)+1.5);
			ObjShot_SetGraphic(bullet2[i],36);
			Obj_SetSpeed(bullet2[i],1);
			Obj_SetAngle(bullet2[i],Obj_GetAngle(bullet2[i])+rand(-45,45));
			reflect2[i]=1;
			}

		h++;
		}
		if(GetCommonDataDefault("ResetAbsorb",0)==1 && reflect2[i]==1){
		let angle=rand(0,360);
		let color=1;
			if(shottype%2==0){
				loop(2){
				CreateShot12(Obj_GetX(bullet2[i]),Obj_GetY(bullet2[i]),1*cos(angle),rand(-0.3,-1),-0.015*cos(angle),rand(0.01,0.025),0.4*cos(angle),rand(2,3),183,0);
				angle+=360/2;
				}
			}
			if(shottype%2!=0){
				loop(3){
				CreateShot02(Obj_GetX(bullet2[i]),Obj_GetY(bullet2[i]),1.5,angle,-0.1,0.75,180+color,10);
				angle+=360/3;
				}
			}
		Obj_Delete(bullet2[i]);
		}
	timer2[i]=timer2[i]+1;
	}
i++;
}
if(GetCommonDataDefault("ResetAbsorb",0)==1){ SetCommonData("ResetAbsorb",0); shottype++; bursttime=90; }


if(time%150==0 && time>=60){
let angle=0;
	loop(15){
	let speed=3;
	let angle2=0;
		loop(20){
		SetShotDirectionType(PLAYER);
			if(time%300==0){ CreateShot01(GetX+10,GetY-30,speed,angle+angle2,153,0); }
			if(time%300!=0){ CreateShot01(GetX+10,GetY-30,speed,angle-angle2,165,0); }
		SetShotDirectionType(ABSOLUTE);
		speed-=0.1;
		angle2+=2.5;
		}
	angle+=360/15;
	}
usespell=30;
PlaySE(SEshotm3);
}


if(time%400==0 && time>=90){
let angle=GetAngleToPlayer;
	loop(6){
		loop(5){
		effect2=(Obj_Create(OBJ_EFFECT));
		Obj_SetPosition(effect2,GetX,GetY);
		ObjEffect_SetScale(effect2,0,0);
		Obj_SetSpeed(effect2,0); Obj_SetAngle(effect2,angle);
		ObjEffect_SetLayer(effect2,3); ObjEffect_SetTexture(effect2,EFmoon); ObjEffect_SetRenderState(effect2,ADD);
		ObjEffect_SetPrimitiveType(effect2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect2,4);
		ObjEffect_SetVertexXY(effect2,0,-80,-80); ObjEffect_SetVertexUV(effect2,0,0,0);
		ObjEffect_SetVertexXY(effect2,1,80,-80); ObjEffect_SetVertexUV(effect2,1,159,0);
		ObjEffect_SetVertexXY(effect2,2,-80,80); ObjEffect_SetVertexUV(effect2,2,0,159);
		ObjEffect_SetVertexXY(effect2,3,80,80); ObjEffect_SetVertexUV(effect2,3,159,159);
		ObjEffect_SetVertexColor(effect2,0,255,255,50,255); ObjEffect_SetVertexColor(effect2,1,255,255,50,255);
		ObjEffect_SetVertexColor(effect2,2,255,255,50,255); ObjEffect_SetVertexColor(effect2,3,255,255,50,255);
		object2=object2~[effect2];
		timer2=timer2~[effect2];
		timer2[length(object2)-1]=0;
		scale2=scale2~[effect2];
		scale2[length(object2)-1]=0;
		moonsize2=moonsize2~[effect2];
		moonsize2[length(object2)-1]=moonsize;
		}
	angle+=360/6;
	}
PlaySE(SEspawn1);
usespell=-30;
if(moonsize<1.6){ moonsize+=0.1; }
}

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

	if(scale2[i]<moonsize2[i]){ scale2[i]=scale2[i]+0.1; }
	else{ Obj_SetSpeed(object2[i],0.4); }

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



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,300,300);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	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",9); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}