script_enemy_main{

let angle1=0;
let radius1=5;
let spirallength1=0;
let xpos1=GetClipMinX+100;
let ypos1=GetClipMinY+120;
let angle2=180;
let radius2=5;
let spirallength2=0;
let xpos2=GetClipMaxX-100;
let ypos2=GetClipMinY+120;

let shot1=0;
let bullet1=[];
let timer1=[];
let shot2=0;
let bullet2=[];
let timer2=[];

let bgscroll=[0,225,450,675];
let bgpos=[rand(-200,0),rand(0,200),rand(-200,0),rand(0,200)];
let bgsize=[rand(0.6,1),rand(0.6,1),rand(0.6,1),rand(0.6,1)];

let effect1=0;
let dial=[];
let dialscale=0;
let dialangle=0;   //45=spring 135=summer 225=autumn 315=winter 
let dialcolor=128;
let dialspin=0;

let character="Ayano";
let cutin=character;
let dispelled=0;
let spellcards=2;
let spellcardnumber=11;
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 EFdial=("\script\Images\BackgroundLayers\Ayano1.png");
let SEdialturn1=("script\SoundEffects\stone1.wav");
let SEdialturn2=("script\SoundEffects\stone2.wav");

let SEfire1=("script\SoundEffects\fire1.wav");
let SEshotb1=("script\SoundEffects\shotb1.wav");

let BG1=("\script\Images\BackgroundLayers\Ayano2.png");
let BG2=("\script\Images\BackgroundLayers\Ayano3.png");
let BG3=("\script\Images\BackgroundLayers\Ayano4.png");
let GRboss=("\script\Images\CharacterSprites\Ayano.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\ShotsAyano1.txt");

	LoadGraphic("\script\Images\BackgroundLayers\Ayano1.png");
	LoadSE("script\SoundEffects\stone1.wav");
	LoadSE("script\SoundEffects\stone2.wav");
	LoadSE("script\SoundEffects\shotb1.wav");

	LoadSE("script\SoundEffects\fire1.wav");

	LoadGraphic("\script\Images\CharacterSprites\Ayano.png");
	LoadGraphic("\script\Images\BackgroundLayers\Ayano2.png");
	LoadGraphic("\script\Images\BackgroundLayers\Ayano3.png");
	LoadGraphic("\script\Images\BackgroundLayers\Ayano4.png");

	SetScore(150000);
	SetLife(350);
	SetTimer(48);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);

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

	SetMovePosition02(cx,miny+100,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=7; }
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("Summer [Katorisenko] ("~difficulty~")",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+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(time%240==0 && time>=240 && GetTimer>0){
	let angle=GetAngleToPlayer;
	loop(12){
	CreateShot02(GetX,GetY,4,angle,-0.1,1.5,88,0);
	angle+=360/12;
	}
usespell=-30;
PlaySE(SEshotb1);
}


if(frame>=30 && frame<120){
SetShotColor(100,100,100);
	loop(2){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,xpos1+radius1*cos(angle1),ypos1+radius1*sin(angle1));
	Obj_SetAngle(shot1,angle1+90);
	Obj_SetSpeed(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,17);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=2780-(spirallength1*15);
	radius1+=0.5;
	angle1-=8;
	spirallength1+=1;
	}
	loop(2){
	shot2=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot2,xpos2+radius2*cos(angle2),ypos2+radius2*sin(angle2));
	Obj_SetAngle(shot2,angle2+90);
	Obj_SetSpeed(shot2,0);
	Obj_SetAutoDelete(shot2,false);
	ObjShot_SetBombResist(shot2,true);
	ObjShot_SetGraphic(shot2,17);
	bullet2=bullet2~[shot2];
	timer2=timer2~[shot2];
	timer2[length(bullet2)-1]=2780-(spirallength2*15);
	radius2+=0.5;
	angle2-=8;
	spirallength2+=1;
	}
SetShotColor(255,255,255);
}

if(frame>=30){
let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); timer1=erase(timer1,i); i--; }
		else{
			if(timer1[i]==30){ ObjShot_SetGraphic(bullet1[i],24); }
			if(timer1[i]==0){
			let shot1=0;
			let angle=time/3;
				loop(20){
				CreateShotA(shot1,Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),10);
				SetShotDataA(shot1,0,2.5,angle,0,0,0,97);
				FireShot(shot1);
				angle-=360/20;
				}
			PlaySE(SEfire1);
			Obj_Delete(bullet1[i]);
			}
		timer1[i]=timer1[i]-1;
		}
	i++;
	}
}
if(frame>=30){
let i=0;
	while(i<length(bullet2)){
		if(Obj_BeDeleted(bullet2[i])){ bullet2=erase(bullet2,i); timer2=erase(timer2,i); i--; }
		else{
			if(timer2[i]==30){ ObjShot_SetGraphic(bullet2[i],24); }
			if(timer2[i]==0){
			let shot1=0;
			let angle=time/3;
				loop(20){
				CreateShotA(shot1,Obj_GetX(bullet2[i]),Obj_GetY(bullet2[i]),10);
				SetShotDataA(shot1,0,2.5,angle,0,0,0,98);
				FireShot(shot1);
				angle+=360/20;
				}
			Obj_Delete(bullet2[i]);
			}
		timer2[i]=timer2[i]-1;
		}
	i++;
	}
}

if(frame==0){
let hpos=0;
	loop(4){
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,cx,miny+150);
	ObjEffect_SetAngle(effect1,0,0,0);
	ObjEffect_SetScale(effect1,0,0);
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,EFdial); ObjEffect_SetRenderState(effect1,ALPHA);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-150,-150); ObjEffect_SetVertexUV(effect1,0,0+hpos,0);
	ObjEffect_SetVertexXY(effect1,1,150,-150); ObjEffect_SetVertexUV(effect1,1,300+hpos,0);
	ObjEffect_SetVertexXY(effect1,2,-150,150); ObjEffect_SetVertexUV(effect1,2,0+hpos,300);
	ObjEffect_SetVertexXY(effect1,3,150,150); ObjEffect_SetVertexUV(effect1,3,300+hpos,300);
	ObjEffect_SetVertexColor(effect1,0,255,255,255,255); ObjEffect_SetVertexColor(effect1,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,255,255,255,255); ObjEffect_SetVertexColor(effect1,3,255,255,255,255);
	dial=dial~[effect1];
	hpos+=300;
	}
dialspin=135;
}

if(frame>=0){
let i=0;
	loop(4){
	ObjEffect_SetScale(dial[i],dialscale,dialscale);
	i++;
	}

if(dialscale<1){ dialscale+=0.05; if(dialscale>=1){ PlaySE(SEdialturn1); } }
if(dialspin>0 && dialscale>=1){ dialangle+=1; dialspin--; }
if(dialspin<0 && dialscale>=1){ dialangle-=1; dialspin++; }
if(dialspin==0 && dialcolor==130){ StopSE(SEdialturn1); PlaySE(SEdialturn2); }

if(dialspin==0 && dialcolor<255){ dialcolor+=2; }
ObjEffect_SetVertexColor(dial[2],0,dialcolor,255,255,255); ObjEffect_SetVertexColor(dial[2],1,dialcolor,255,255,255);
ObjEffect_SetVertexColor(dial[2],2,dialcolor,255,255,255); ObjEffect_SetVertexColor(dial[2],3,dialcolor,255,255,255);

ObjEffect_SetAngle(dial[1],0,0,dialangle);
ObjEffect_SetAngle(dial[2],0,0,dialangle);
ObjEffect_SetAngle(dial[3],0,0,dialangle);
}

if(frame==-30){ 
	SetColor(255,160,200);
	Concentration01(90);
	SetColor(255,255,255);
}


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

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

	SetGraphicRect(0,0,300,300);
	SetTexture(BG3);
	SetAlpha(255);
	SetColor(bgfade/2,bgfade/2,bgfade/2);
	SetGraphicScale(2,2);
	SetGraphicAngle(0,0,-time/7);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,400,400);
	SetTexture(BG1);
	SetAlpha(255);
	SetColor(bgfade*0.6,bgfade*0.6,bgfade*0.6);
	SetGraphicScale(1.5,1.5);
	SetGraphicAngle(0,0,time/10);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,400,400);
	SetTexture(BG2);
	SetAlpha(255);
	SetColor(bgfade*0.8,bgfade*0.8,bgfade*0.8);
	SetRenderState(ALPHA);
	let i=0;
		loop(4){
		SetGraphicScale(bgsize[i],bgsize[i]);
			if(i%2==0){ SetGraphicAngle(0,0,time); }
			if(i%2!=0){ SetGraphicAngle(0,0,-time);}
		DrawGraphic(cx+bgpos[i],bgscroll[i]);
		bgscroll[i]=bgscroll[i]+1.5;
		if(bgscroll[i]>700){
			bgscroll[i]=-200;
			if(i%2==0){ bgpos[i]=rand(-200,0); SetGraphicAngle(0,0,time); }
			if(i%2!=0){ bgpos[i]=rand(0,200); SetGraphicAngle(0,0,-time);}
			bgsize[i]=rand(0.6,1);
			}
		
		i++;
		}
}

@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{
//	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}