script_enemy_main{

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

let character="Amaya";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=9;
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 SEshots3=("\script\SoundEffects\shots3.wav");
let SEcharge4=("\script\SoundEffects\charge4.wav");

let BG1=("\script\Images\BackgroundLayers\Witches1.png");
let BG2=("\script\Images\BackgroundLayers\Amaya1.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\shots3.wav");
	LoadSE("\script\SoundEffects\charge4.wav");

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

	SetScore(150000);
	SetLife(225);
	SetTimer(40);
	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(32,32,32,32);

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("[Once In A Blue Moon] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


if(time%6==0 && time>=60){
let angle=time*0.6;
	loop(5){
	CreateShot02(GetX,GetY,3,angle+60*cos(time+0),-0.05,2,165,0);
	CreateShot02(GetX,GetY,3.5,-angle+60*cos(time+90),-0.05,2,153,0);
	CreateShot02(GetX,GetY,3,angle+60*cos(time+180),-0.05,2,165,0);
	CreateShot02(GetX,GetY,3.5,-angle+60*cos(time+270),-0.05,2,153,0);
	angle+=360/5;
	}
PlaySE(SEshots3);
}


if((time+270)%400==0 && time>=90){
	SetColor(180,0,180);
	Concentration01(90);
	SetColor(255,255,255);
PlaySE(SEcharge4);
}

if((time+220)%400==0 && time>=90){
let angle=GetAngleToPlayer;
	loop(7){
	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,50,50,255); ObjEffect_SetVertexColor(effect1,1,255,50,50,255);
	ObjEffect_SetVertexColor(effect1,2,255,50,50,255); ObjEffect_SetVertexColor(effect1,3,255,50,50,255);
	object1=object1~[effect1];
	timer1=timer1~[effect1];
	timer1[length(object1)-1]=0;
	scale1=scale1~[effect1];
	scale1[length(object1)-1]=0;
	}
PlaySE(SEspawn1);
usespell=-30;
}

let i=0; timer1=timer1~[effect1];
while(i<length(object1)){
	timer1[i]=timer1[i]+1;
	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]<2){ scale1[i]=scale1[i]+0.1; }
	else{ Obj_SetSpeed(object1[i],0.5); }

	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,512,512);
	SetGraphicScale(1,1);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,time/7);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(1.3,1.3);
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetColor(150,150,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(GetX,GetY);
}

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

}