script_enemy_main{

let effect1=0;
let object1=[];
let timer1=[];
let scale1=[];

let shot2=0;
let bullet2=[];
let timer2=[];
let ypos2=[];
let ypos1=[];

let ypos=GetCenterY;
let wave=rand(0,360);
let ywave=rand(0,360);
let bulletspeed=1.5;

let character="Amaya";
let cutin=character;
let dispelled=0;
let spellcards=3;
let spellcardnumber=7;
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 BG1=("\script\Images\BackgroundLayers\Amaya4.png");
let GRboss=("\script\Images\CharacterSprites\Amaya.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\ShotsAmaya1.txt");

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

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

	SetScore(150000);
	SetLife(225);
	SetTimer(35);
	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);
}
	
@MainLoop{

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

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

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


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


ypos=cy+50*cos(wave/2);
wave++;

if(time%35==0 && time>=60){
let posx=0;
let color=0;
	loop(3){
	shot2=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot2,minx-posx,ypos);
	Obj_SetAngle(shot2,0);
	Obj_SetSpeed(shot2,0.8);
	ObjShot_SetBombResist(shot2,true);
	if(color%2==0){ ObjShot_SetGraphic(shot2,175); }
	if(color%2!=0){ ObjShot_SetGraphic(shot2,176); }
	bullet2=bullet2~[shot2];
	timer2=timer2~[shot2];
	timer2[length(bullet2)-1]=0;
	ypos1=ypos1~[shot2];
	ypos1[length(bullet2)-1]=posx*3;
	ypos2=ypos2~[shot2];
	ypos2[length(bullet2)-1]=ywave;
	posx+=30;
	color++;
	}
ywave+=20;
}
let i=0;
while(i<length(bullet2)){
	if(Obj_BeDeleted(bullet2[i])){
	bullet2=erase(bullet2,i); timer2=erase(timer2,i); ypos1=erase(ypos1,i); ypos2=erase(ypos2,i);
	i--;
	}
	else{
	Obj_SetY(bullet2[i],ypos+ypos1[i]+15*cos(ypos2[i]));
	ypos2[i]=ypos2[i]+2;
	timer2[i]=timer2[i]+1;
	}
i++;
}


if(time%250==0 && time>=60){
let angle=0;
if(time%500==0){ angle=0; }
if(time%500!=0){ angle=360/12; }
	loop(6){
		loop(4){
		effect1=(Obj_Create(OBJ_EFFECT));
		Obj_SetPosition(effect1,GetX,GetY);
		ObjEffect_SetScale(effect1,0,0);
		Obj_SetSpeed(effect1,0); Obj_SetAngle(effect1,angle);
		ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,EFmoon); ObjEffect_SetRenderState(effect1,ADD);
		ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
		ObjEffect_SetVertexXY(effect1,0,-80,-80); ObjEffect_SetVertexUV(effect1,0,0,0);
		ObjEffect_SetVertexXY(effect1,1,80,-80); ObjEffect_SetVertexUV(effect1,1,159,0);
		ObjEffect_SetVertexXY(effect1,2,-80,80); ObjEffect_SetVertexUV(effect1,2,0,159);
		ObjEffect_SetVertexXY(effect1,3,80,80); ObjEffect_SetVertexUV(effect1,3,159,159);
		ObjEffect_SetVertexColor(effect1,0,255,150,150,150); ObjEffect_SetVertexColor(effect1,1,255,150,150,150);
		ObjEffect_SetVertexColor(effect1,2,255,150,150,150); ObjEffect_SetVertexColor(effect1,3,255,150,150,150);
		object1=object1~[effect1];
		timer1=timer1~[effect1];
		timer1[length(object1)-1]=0;
		scale1=scale1~[effect1];
		scale1[length(object1)-1]=0;
		}
	angle+=360/6;
	}
PlaySE(SEspawn1);
usespell=-30;
}

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

	if(scale1[i]<1){ scale1[i]=scale1[i]+0.1; }
	else{ Obj_SetSpeed(object1[i],0.65); }

	timer1[i]=timer1[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";
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }
	SetGraphicRect(0,0,300,300);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG1);
	SetAlpha(bgfade*0.6);
	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{
//	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}