script_enemy_main{

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

let character="SayuriMai";
let cutin=character;
let dispelled=0;
let spellcards=5;
let spellcardnumber=13;
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 SEshots6=("script\SoundEffects\shots6.wav");
let BG1=("\script\Images\BackgroundLayers\Sayuri1.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\ShotsSayuriMai1.txt");

	LoadGraphic("\script\Images\CharacterSprites\Sayuri.png");
	LoadGraphic("\script\Images\CharacterSprites\Mai.png");
	LoadGraphic("\script\Images\BackgroundLayers\Sayuri1.png");

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

	SetScore(200000);
	SetLife(400);
	SetTimer(40);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(false);
	MagicCircle(false);
	SetX(cx);
	SetY(miny-1000);

	SetCommonData("UseSpell1",0);
	SetCommonData("UseSpell2",0);
	
	SetCommonData("Boss1Vanish",1);
	SetCommonData("Boss2Vanish",1);
}
	
@MainLoop{

SetCollisionA(GetCommonData("Boss1X"),GetCommonData("Boss1Y"),16);
SetCollisionA(GetCommonData("Boss2X"),GetCommonData("Boss2Y"),16);
SetCollisionB(GetCommonData("Boss1X"),GetCommonData("Boss1Y"),16);
SetCollisionB(GetCommonData("Boss2X"),GetCommonData("Boss2Y"),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=4; }
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("Gimmick [Optical Illusion] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

if(time==0){
CreateEnemyFromFile(GetCurrentScriptDirectory~"Sayuri-Mai - Optical Illusion - Sayuri.txt",GetCommonData("Boss1X"),GetCommonData("Boss1Y"),0,0,0);
CreateEnemyFromFile(GetCurrentScriptDirectory~"Sayuri-Mai - Optical Illusion - Mai.txt",GetCommonData("Boss2X"),GetCommonData("Boss2Y"),0,0,0);
}


let boss1x=GetCommonData("Boss1X");
let boss1y=GetCommonData("Boss1Y");
let boss2x=GetCommonData("Boss2X");
let boss2y=GetCommonData("Boss2Y");

if(time>=120 && time%4==0){
let angle=time*1.26;
	loop(6){
	let shot1=0;
	let delay=0;
let radius=80+20*cos(time);
	CreateShotA(shot1,boss1x+radius*cos(angle),boss1y+radius*sin(angle),10);
	SetShotDataA(shot1,0,1.5,angle,0,0,0,14);
		loop(8){
		SetShotDataA(shot1,delay,NULL,NULL,0,0.02,1.5,14);
		SetShotDataA(shot1,45+delay,NULL,NULL,0,-0.02,0.5,38);
		delay+=90;
		}
	FireShot(shot1);
	angle+=360/6;
	}
	loop(6){
	let shot1=0;
	let delay=0;
let radius=80+20*cos(time+180);
	CreateShotA(shot1,boss2x+radius*cos(-angle),boss2y+radius*sin(-angle),10);
	SetShotDataA(shot1,0,1.5,-angle,0,0,0,4);
		loop(8){
		SetShotDataA(shot1,delay,NULL,NULL,0,0.02,1.5,4);
		SetShotDataA(shot1,45+delay,NULL,NULL,0,-0.02,0.5,28);
		delay+=90;
		}
	FireShot(shot1);
	angle+=360/6;
	}
PlaySE(SEshots6);
SetCommonData("UseSpell1",30);
SetCommonData("UseSpell2",30);
}


if(time%80==0 && time>=60){
let angle2=rand(0,360);
	loop(50){
	shot1=(Obj_Create(OBJ_SHOT));
	if((time+0)%160==0){ Obj_SetPosition(shot1,boss1x,boss1y); }
	if((time+80)%160==0){ Obj_SetPosition(shot1,boss2x,boss2y); }
	Obj_SetAngle(shot1,angle2);
	Obj_SetSpeed(shot1,3);
	ObjShot_SetGraphic(shot1,57);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle2+=360/50;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); timer1=erase(timer1,i); i--; }
	else{
	Obj_SetSpeed(bullet1[i],Obj_GetSpeed(bullet1[i])-3/60);
	if(timer1[i]==30){ ObjShot_FadeDelete(bullet1[i]); }
	timer1[i]=timer1[i]+1;
	}
i++;
}


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";
}

@BackGround{
	if(bgfade<180){ bgfade+=5; }
	SetGraphicRect(0,0+(time/2),520,520+(time/2));
	SetGraphicScale(1,1);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
}

@DrawLoop{
}

@Finalize{
//	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}