script_enemy_main{

let shoot=60;
let melonangle=rand(0,360);
let soundpause=0;

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

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

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 spellcards=8;
let spellcardnumber=50;
let dispelled=0;
let damagerate=10;
let outfit=5;
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 EFdial=("\script\Images\BackgroundLayers\Ayano1.png");
let SEdialturn1=("script\SoundEffects\stone1.wav");
let SEdialturn2=("script\SoundEffects\stone2.wav");

let SEshotb6=("script\SoundEffects\shotb6.wav");
let SEshotb7=("script\SoundEffects\shotb7.wav");

let BG1=("\script\Images\BackgroundLayers\Takeo3.png");
let BG2=("\script\Images\BackgroundLayers\Ayano3.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\shotb6.wav");
	LoadSE("script\SoundEffects\shotb7.wav");

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

	SetScore(750000);
	SetLife(500);
	SetTimer(60);
	SetInvincibility(180);
	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"));
	SetMovePosition02(cx,miny+150,50);

	SetCommonData("Boss1Vanish",1);
}
	
@MainLoop{

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

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=2.5; }
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 [Suikawari]",spellcardnumber); 
HealthBar();
Portrait(cutin,2);


if(frame==shoot && time>=60){
let angle=rand(0,360);
let radius=120;
let size=25+(time/180);
	loop(40){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,(GetX+radius*cos(melonangle))+size*cos(angle),(GetY+radius*sin(melonangle))+size*sin(angle));
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetDelay(shot1,10);
	ObjShot_SetGraphic(shot1,29);
	bullet1=bullet1~[shot1];
	collide1=collide1~[shot1];
	collide1[length(bullet1)-1]=0;
	collidetime1=collidetime1~[shot1];
	collidetime1[length(bullet1)-1]=0;
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle+=360/40;
	}

	shot2=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot2,GetX,GetY);
	Obj_SetAngle(shot2,melonangle+180);
	Obj_SetSpeed(shot2,3);
	ObjShot_SetGraphic(shot2,63);
	bullet2=bullet2~[shot2];
	bounce2=bounce2~[shot2];
	bounce2[length(bullet2)-1]=0;
frame=0;
melonangle+=56;
usespell=-20;
PlaySE(SEshotb6);
}
if(time%300==0 && shoot>30 && time>=60){ shoot-=5; }


if(time>=60){
let i=0;
	while(i<length(bullet2)){
		if(Obj_BeDeleted(bullet2[i])){
		bullet2=erase(bullet2,i); bounce2=erase(bounce2,i);
		i--;
		}
		else{
		let obj=bullet2[i];
			if(bounce2[i]<2){
				if(Obj_GetX(obj)<=minx){
				Obj_SetAngle(obj,180-Obj_GetAngle(obj));
				Obj_SetX(obj,Obj_GetX(obj)+1); bounce2[i]=bounce2[i]+1;
				}
				if(Obj_GetX(obj)>=maxx){
				Obj_SetAngle(obj,180-Obj_GetAngle(obj));
				Obj_SetX(obj,Obj_GetX(obj)-1); bounce2[i]=bounce2[i]+1;
				}
				if(Obj_GetY(obj)<=miny){
				Obj_SetAngle(obj,-Obj_GetAngle(obj));
				Obj_SetY(obj,Obj_GetY(obj)+1); bounce2[i]=bounce2[i]+1;
				}
				if(Obj_GetY(obj)>=maxy){
				Obj_SetAngle(obj,-Obj_GetAngle(obj));
				Obj_SetY(obj,Obj_GetY(obj)-1); bounce2[i]=bounce2[i]+1;
				}
			}
			if(bounce2[i]==1){ ObjShot_SetGraphic(bullet2[i],62); }
			if(bounce2[i]==2){ ObjShot_SetGraphic(bullet2[i],61); }
		}
	i++;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); collide1=erase(collide1,i); collidetime1=erase(collidetime1,i); timer1=erase(timer1,i);
	i--;
	}
	else{
		let h=0;
		while(h<length(bullet2)){
			if(collide1[i]<1 && (((Obj_GetX(bullet2[h])-Obj_GetX(bullet1[i]))^2+(Obj_GetY(bullet2[h])-Obj_GetY(bullet1[i]))^2)^0.5)<40){
			let random=rand_int(0,6);
			if(random>=4){ CreateShot01(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),rand(2,3),Obj_GetAngle(bullet2[h])+rand(-60,60),113,0); }
			collide1[i]=collide1[i]+1;
			if(collidetime1[i]<30){ collidetime1[i]=collidetime1[i]+2; }
			}
			if(collide1[i]>=1 && collidetime1[i]>0 && (((Obj_GetX(bullet2[h])-Obj_GetX(bullet1[i]))^2+(Obj_GetY(bullet2[h])-Obj_GetY(bullet1[i]))^2)^0.5)<40){
			let random=rand_int(0,6);
			if(random>=4){ CreateShot01(Obj_GetX(bullet2[h]),Obj_GetY(bullet2[h]),rand(2,3),Obj_GetAngle(bullet2[h])+rand(-45,45),109,0); }
			}
			if(collide1[i]>=1 && collidetime1[i]==0 && (((Obj_GetX(bullet2[h])-Obj_GetX(bullet1[i]))^2+(Obj_GetY(bullet2[h])-Obj_GetY(bullet1[i]))^2)^0.5)<40){
			if(soundpause==0){ PlaySE(SEshotb7); soundpause=5; }
			Obj_Delete(bullet1[i]);
			}
		h++;
		}
	if(collidetime1[i]>0){ collidetime1[i]=collidetime1[i]-1; }
	if(timer1[i]==210){ ObjShot_FadeDelete(bullet1[i]); }
	timer1[i]=timer1[i]+1;
	}
i++;
}
if(soundpause>0){ soundpause--; }


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


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,280,300);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(130,130,130);
	SetGraphicScale(2,2);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,400,400);
	SetTexture(BG2);
	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,5);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}