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 character="Mai";
let cutin=character;
let dispelled=0;
let spellcards=4;
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(180);
	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==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(time%20==0 && time>=60){
	SetMovePosition02(cx+80*cos(time),miny+50+20*sin(time*2),50);
}

if(frame==randomtime){
SetCommonData("Difficulty",4);
	CreateEnemyFromFile((GetCurrentScriptDirectory~"Mai - Dancing Furin - Familiar.txt"),GetX,GetY,0,0,color);
	color+=rand_int(1,3);
	if(color>10){ color-=10; }
	frame=0;
	randomtime=rand_int(100,110);
}


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

}