script_enemy_main{

let shootspeed=1;
let playsound=0;

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

let effect2=0;
let object2=[];
let timer2=[];
let type2=[];
let size2=[];
let speed2=[];

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 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 character="Ayano";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=72;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=-180;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshots6=("script\SoundEffects\shots6.wav");
let SEshotm4=("script\SoundEffects\shotm4.wav");

let EFdial=("\script\Images\BackgroundLayers\Ayano1.png");
let SEdialturn1=("script\SoundEffects\stone1.wav");
let SEdialturn2=("script\SoundEffects\stone2.wav");

let EFbird=("\script\Images\OtherEffects\Phoenix.png");

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\CharacterSprites\Ayano.png");
	LoadGraphic("\script\Images\BackgroundLayers\Ayano1.png");
	LoadGraphic("\script\Images\BackgroundLayers\Ayano2.png");
	LoadGraphic("\script\Images\BackgroundLayers\Ayano3.png");
	LoadGraphic("\script\Images\BackgroundLayers\Ayano4.png");

	LoadGraphic("\script\Images\OtherEffects\Phoenix.png");

	LoadSE("script\SoundEffects\shots6.wav");
	LoadSE("script\SoundEffects\shotm4.wav");
	LoadSE("script\SoundEffects\stone1.wav");
	LoadSE("script\SoundEffects\stone2.wav");

	SetScore(2500000);
	SetLife(650);
	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+100,50);

	SetDurableSpellCard;
}
	
@MainLoop{

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

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("Summer [Vermilion Bird Of The South]",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%(10-((shootspeed-1)*5))==0 && time>=240){
let color=0;
let shot=0;
let angle=-time*1.1;
	loop(7){
	if(shot==0){ color=13; }
	if(shot==1){ color=14; }
	if(shot==2){ color=15; }
	if(shot==3){ color=17; }
	if(shot==4){ color=19; }
	if(shot==5){ color=20; }
	if(shot==6){ color=21; }
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY-10);
	Obj_SetAngle(shot1,angle*shootspeed);
	Obj_SetSpeed(shot1,6);
	ObjShot_SetGraphic(shot1,color);
	ObjShot_SetDelay(shot1,10);
	ObjShot_SetBombResist(shot1,true);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle+=360/7;
	shot++;
	}
PlaySE(SEshots6);
usespell=15;
}
if(GetLife<100 || GetTimer<10){ shootspeed=2; }

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i);
	i--;
	}
	else{
	if(Obj_GetSpeed(bullet1[i])>1.5){ Obj_SetSpeed(bullet1[i],Obj_GetSpeed(bullet1[i])-0.1); }
		let h=0;
		while(h<length(object2)){
			if((((Obj_GetX(object2[h])-Obj_GetX(bullet1[i]))^2+(Obj_GetY(object2[h])-Obj_GetY(bullet1[i]))^2)^0.5)<35){
			ObjShot_SetGraphic(bullet1[i],24);
			Obj_SetSpeed(bullet1[i],0.3);
			}
		h++;
		}
	timer1[i]=timer1[i]+1;
	}
i++;
}


if(time==180 || time==300){
let xsize=80;
let ysize=80;
let picture=0;
let color=255;
let type=0;
	loop(2){
	effect2=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect2,GetPlayerX,maxy+50);
	Obj_SetAngle(effect2,270);
	ObjEffect_SetAngle(effect2,0,0,0);
	ObjEffect_SetScale(effect2,1.5,1.5);
	Obj_SetAutoDelete(effect2,false);
	ObjEffect_SetLayer(effect2,3); ObjEffect_SetTexture(effect2,EFbird); ObjEffect_SetRenderState(effect2,ADD);
	ObjEffect_SetPrimitiveType(effect2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect2,4);
	ObjEffect_SetVertexXY(effect2,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect2,0,0+picture,0);
	ObjEffect_SetVertexXY(effect2,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect2,1,xsize+picture,0);
	ObjEffect_SetVertexXY(effect2,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect2,2,0+picture,ysize);
	ObjEffect_SetVertexXY(effect2,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect2,3,xsize+picture,ysize);
	ObjEffect_SetVertexColor(effect2,0,color,255,255,255); ObjEffect_SetVertexColor(effect2,1,color,255,255,255);
	ObjEffect_SetVertexColor(effect2,2,color,255,255,255); ObjEffect_SetVertexColor(effect2,3,color,255,255,255);
	object2=object2~[effect2];
	timer2=timer2~[effect2];
	timer2[length(object2)-1]=0;
	type2=type2~[effect2];
	type2[length(object2)-1]=type;
	size2=size2~[effect2];
	size2[length(object2)-1]=1;
	speed2=speed2~[effect2];
	speed2[length(object2)-1]=1;
	picture+=80;
	color-=150;
	type++;
	}
}

let i=0;
while(i<length(object2)){
	if(Obj_BeDeleted(object2[i])){
	object2=erase(object2,i); timer2=erase(timer2,i); type2=erase(type2,i); size2=erase(size2,i); speed2=erase(speed2,i);
	i--;
	}
	else{
	
	if(timer2[i]==0){
	let shotx=0;
	CreateLaserA(shotx,Obj_GetX(object2[i]),Obj_GetY(object2[i]),600,10,131,150);
	SetLaserDataA(shotx,0,Obj_GetAngle(object2[i]),0,0,0,0);
	SetShotKillTime(shotx,149);
	FireShot(shotx);
	}
	
	if(Obj_GetX(object2[i])>maxx+70 || Obj_GetX(object2[i])<minx-70 || Obj_GetY(object2[i])>maxy+70 || Obj_GetY(object2[i])<miny-70 && timer2[i]>=60){
	Obj_SetAngle(object2[i],atan2(GetPlayerY-Obj_GetY(object2[i]),GetPlayerX-Obj_GetX(object2[i])));
	ObjEffect_SetAngle(object2[i],0,0,Obj_GetAngle(object2[i])+90);
	Obj_SetSpeed(object2[i],0);
	if(size2[i]<7){ size2[i]=size2[i]+0.5; }
	if(speed2[i]<2.5){ speed2[i]=speed2[i]+0.1; }
		
	let shotx=0;
	CreateLaserA(shotx,Obj_GetX(object2[i]),Obj_GetY(object2[i]),600,10,131,150);
	SetLaserDataA(shotx,0,Obj_GetAngle(object2[i]),0,0,0,0);
	SetShotKillTime(shotx,149);
	FireShot(shotx);
	
	timer2[i]=0;
	}

	if(timer2[i]%(12-round(speed2[i]))==0 && type2[i]==0){
	let shotx=0;
	let speed=1;
	let color=1;
	let shot=0;
	let angle=Obj_GetAngle(object2[i])-90;
		loop(size2[i]){
		if(shot==0){ color=1; }
		if(shot==1){ color=2; }
		if(shot==2){ color=3; }
		if(shot==3){ color=5; }
		if(shot==4){ color=7; }
		if(shot==5){ color=8; }
		if(shot==6){ color=9; }
		CreateShotA(shotx,Obj_GetX(object2[i])+7*cos(angle),Obj_GetY(object2[i])+7*sin(angle),10);
		SetShotDataA(shotx,0,0,angle,0,0,0,72+color);
		SetShotDataA(shotx,10,0,NULL,0,0.015*speed,speed,72+color);
		FireShot(shotx);
		speed+=0.25;
		shot++;
		}
	let shotx=0;
	let speed=1;
	let color=1;
	let shot=0;
	let angle=Obj_GetAngle(object2[i])+90;
		loop(size2[i]){
		if(shot==0){ color=1; }
		if(shot==1){ color=2; }
		if(shot==2){ color=3; }
		if(shot==3){ color=5; }
		if(shot==4){ color=7; }
		if(shot==5){ color=8; }
		if(shot==6){ color=9; }
		CreateShotA(shotx,Obj_GetX(object2[i])+7*cos(angle),Obj_GetY(object2[i])+7*sin(angle),10);
		SetShotDataA(shotx,0,0,angle,0,0,0,72+color);
		SetShotDataA(shotx,10,0,NULL,0,0.015*speed,speed,72+color);
		FireShot(shotx);
		speed+=0.25;
		shot++;
		}
	if(playsound==0 && timer2[i]>=45){ PlaySE(SEshotm4); playsound=7; }
	}
	
	if(Obj_GetSpeed(object2[i])<3*speed2[i]){ Obj_SetSpeed(object2[i],Obj_GetSpeed(object2[i])+0.02*speed2[i]); }
	SetCollisionB(Obj_GetX(object2[i]),Obj_GetY(object2[i]),32);
	
	timer2[i]=timer2[i]+1;
	}
i++;
}
if(playsound>0){ playsound--; }


if(frame==-180){
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>=-180){
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){ 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);

SetCommonData("WarningX",cx);
SetCommonData("WarningSide",3);
SetCommonData("WarningTime",90);
SetCommonData("WarningSize",0.75);
SetCommonData("WarningType",1);
CreateEnemyFromFile("script\Functions\warnings.txt",0,0,0,0,0);
}


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);
	SetTexture(BG3);
	SetAlpha(bgfade);
	SetColor(100,100,100);
	SetGraphicScale(2,2);
	SetGraphicAngle(0,0,-time/7);
	DrawGraphic(cx,cy);

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

	SetGraphicRect(0,0,400,400);
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetColor(150,150,150);
	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); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}

@Finalize{
	if(GotSpellCardBonus){ SetCommonData("LastTrumpCard",5); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}