script_enemy_main{

let GRscore=("\script\Images\OtherEffects\MusicalScore.png");
let EFflag=0;
let EFflagsizex=300;
let EFflagsizey=50;
let EFrealsizex=300;
let EFrealsizey=50;
let EFvertices=50;
let EFwavesize=20;
let EFwaveradius=7;
let EFwave=0;
let EFfade=255;
let EFwavespeed=5;

let randomtime=rand_int(100,110);
let color=rand_int(1,10);
let opening=20;
let swingspeed=3;

let core=0;
let direction=0;
let olddirection=[];

let size=0;
let shot1=0;
let timer1=[];
let glass=[];
let glassangle=[];

let shot2=0;
let timer2=[];
let paper=[];
let paperangle=[];
let paperdistance=[];

let laser=0;

let character="Mai";
let cutin=character;
let dispelled=0;
let spellcards=3;
let spellcardnumber=14;
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 SEchime1=("script\SoundEffects\chime1.wav");

let BG1=("\script\Images\BackgroundLayers\Mai1.png");
let GRboss=("\script\Images\CharacterSprites\Mai.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\ShotsMai1.txt");

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

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

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

	SetScore(200000);
	SetLife(300);
	SetTimer(45);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+80,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("Summer Breeze [Dancing Furin] ("~difficulty~")",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+50,miny+90),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+50,miny+90),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+50,miny+90),1.5);
	}
}


if(time==0){
	EFflag=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFflag,GetX,GetY);
	ObjEffect_SetScale(EFflag,1,1);
	ObjEffect_SetLayer(EFflag,1); ObjEffect_SetTexture(EFflag,GRscore); ObjEffect_SetRenderState(EFflag,ALPHA);
	ObjEffect_SetPrimitiveType(EFflag,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFflag,EFvertices);
}

let i=0;
let xnr=-(EFflagsizex/2);
let ynr=(EFflagsizey/2);
let vnr=0;
EFfade=255;
	loop(EFvertices){
	ObjEffect_SetVertexXY(EFflag,i,xnr,-(EFflagsizey/2)+EFwaveradius*cos((i*EFwavesize)+EFwave));
	ObjEffect_SetVertexXY(EFflag,i+1,xnr,(EFflagsizey/2)+EFwaveradius*cos((i*EFwavesize)+EFwave));
	ObjEffect_SetVertexUV(EFflag,i,vnr,0);
	ObjEffect_SetVertexUV(EFflag,i+1,vnr,EFrealsizey);
	ObjEffect_SetVertexColor(EFflag,i,EFfade,255,255,255);
	ObjEffect_SetVertexColor(EFflag,i+1,EFfade,255,255,255);
	if(i>=(EFvertices/2)){ EFfade-=(255*5)/EFvertices; }
	xnr+=((EFflagsizex)/(EFvertices))*2;
	ynr+=(EFflagsizey/(EFvertices));
	vnr+=((EFrealsizex)/(EFvertices))*2;
	i+=2;
	}
Obj_SetPosition(EFflag,GetX+(EFflagsizex/2),GetY);
EFwave+=EFwavespeed;


if(((GetPlayerX-Obj_GetX(core))^2+(GetPlayerY-Obj_GetY(core))^2)^0.5<40){ ShootDownPlayer; SetPlayerX(cx); SetPlayerY(400); }

if((time+95)%floor(360/swingspeed/2)==0 && time>=90){
let angle=90+opening+direction;
let wavesizea=80;
let wavesizeb=6;
	loop(wavesizea){
	CreateShot01(Obj_GetX(core)+size*cos(angle+olddirection[0]),Obj_GetY(core)+size*sin(angle+olddirection[0]),4,angle,45,0);
	angle+=(360-(opening*2))/(wavesizea-1);
	}
angle-=rand(-6,6)+(360-(opening*2))/(wavesizea-1.5);
angle+=(360-(360-(opening*2)))/(wavesizeb*2);
	loop(wavesizeb){
	let speed=2;
		loop(2){
		CreateShot01(Obj_GetX(core)+size*cos(angle+olddirection[0]),Obj_GetY(core)+size*sin(angle+olddirection[0]),speed,angle,47,0);
		speed-=0.5;
		}
	angle+=(360-(360-(opening*2)))/(wavesizeb);
	}
PlaySE(SEchime1);
}


if(time==60){
let angle=0;
	core=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(core,GetX,GetY);
	Obj_SetAngle(core,0);
	Obj_SetAlpha(core,0);
	ObjShot_SetBombResist(core,true);
	ObjShot_SetGraphic(core,0);

let angle=0;
	loop(101){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,90+opening+angle);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetDelay(shot1,20);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,140);
	glass=glass~[shot1];
	timer1=timer1~[shot1];
	timer1[length(glass)-1]=0;
	glassangle=glassangle~[shot1];
	glassangle[length(glass)-1]=90+opening+angle;
	angle+=((360-(opening*2))/100);
	}

let angle=90;
let count=0;
	loop(12){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetDelay(shot1,20);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,25);
	paper=paper~[shot1];
	timer2=timer2~[shot1];
	timer2[length(paper)-1]=0;
	paperangle=paperangle~[shot1];
	paperangle[length(paper)-1]=90;
	paperdistance=paperdistance~[shot1];
	paperdistance[length(paper)-1]=120-count;
	olddirection=olddirection~[shot1];
	olddirection[length(paper)-1]=0;
	count+=10;
	}

	laser=(Obj_Create(OBJ_LASER));
	Obj_SetPosition(laser,GetX,GetY);
	Obj_SetAngle(laser,90);
	ObjShot_SetDelay(laser,20);
	ObjShot_SetBombResist(laser,true);
	ObjShot_SetGraphic(laser,155);
	ObjLaser_SetLength(laser,120);
	ObjLaser_SetWidth(laser,10);
	ObjLaser_SetSource(laser,false);
}

if(time>=60){
let i=0;
	while(i<length(glass)){
		Obj_SetPosition(glass[i],Obj_GetX(core)+size*cos(1*direction+glassangle[i]+olddirection[0]),Obj_GetY(core)+size*sin(1*direction+glassangle[i]+olddirection[0]));
		Obj_SetAngle(glass[i],glassangle[i]);

		if(timer1[i]>=20){ Obj_SetAlpha(glass[i],255); }
		timer1[i]=timer1[i]+1;
	i++;
	}
let i=0;
	while(i<length(paper)){
		Obj_SetPosition(paper[i],Obj_GetX(core)+(size+35+paperdistance[i])*cos(direction+90+olddirection[i]),Obj_GetY(core)+(size+35+paperdistance[i])*sin(direction+90+olddirection[i]));

		Obj_SetAngle(paper[i],paperangle[i]);

		if(timer2[i]>=20){ Obj_SetAlpha(paper[i],255); }
		timer2[i]=timer2[i]+1;
	i++;
	} 
}



if(time>=60){
if(size<40){ size+=40/20; } 

Obj_SetPosition(core,GetX,GetY+80);
Obj_SetPosition(laser,Obj_GetX(core)-(size)*cos(direction+90+olddirection[0]),Obj_GetY(core)-(size)*sin(direction+90+olddirection[0]));
Obj_SetAngle(laser,direction*2+90);

direction=(opening/4)*cos(time*swingspeed);
olddirection=olddirection~[direction];
olddirection=erase(olddirection,0);
}


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss2X",GetX); SetCommonData("Boss2Y",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+time,0,300+time,300);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG1);
	SetAlpha(bgfade);
	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";
}

}