script_enemy_main{

let spellphase=1;
let phase=rand_int(0,1);
let weave=0;
let size=1;
let laserspeed=0.1;

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

let character="Youko";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=75;
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 SEcharge1=("\script\SoundEffects\charge1.wav");
let SEshots3=("\script\SoundEffects\shots3.wav");
let SEshots5=("\script\SoundEffects\shots5.wav");
let SEshotb5=("\script\SoundEffects\shotb5.wav");
let SElaserb2=("\script\SoundEffects\laserb2.wav");

let GReffect=("\script\Images\OtherEffects\SunBullet.png");
let BG1=("\script\Images\BackgroundLayers\Youko4.png");
let BG2=("\script\Images\BackgroundLayers\Youko5.png");
let GRboss=("\script\Images\CharacterSprites\Youko.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\ShotsYouko1.txt");

	LoadSE("\script\SoundEffects\charge1.wav");
	LoadSE("\script\SoundEffects\shots3.wav");
	LoadSE("\script\SoundEffects\shots5.wav");
	LoadSE("\script\SoundEffects\shotb5.wav");
	LoadSE("\script\SoundEffects\laserb2.wav");

	LoadGraphic("\script\Images\OtherEffects\SunBullet.png");
	LoadGraphic("\script\Images\BackgroundLayers\Youko4.png");
	LoadGraphic("\script\Images\BackgroundLayers\Youko5.png");
	LoadGraphic("\script\Images\CharacterSprites\Youko.png");

	SetScore(2500000);
	SetLife(1000);
	SetTimer(80);
	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);

	SetDurableSpellCard;
}
	
@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=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("Amaterasu Omikami [Yasakani No Magatama]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

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


if(time%6==0 && spellphase>=1 && time>=60){
let angle=0;
let color=0;
	loop(size){
	if((color+0)%3==0){ CreateShot01(cx+10*cos(time)+180*cos(weave+angle),miny,2.5,90,88,10); }
	if((color+1)%3==0){ CreateShot01(cx+10*cos(time)+180*cos(weave+angle),miny,2.5,90,89,10); }
	if((color+2)%3==0){ CreateShot01(cx+10*cos(time)+180*cos(weave+angle),miny,2.5,90,90,10); }
	color++;
	angle+=360/6;
	}
PlaySE(SEshots3);
}
weave+=1.6;
if(size<6 && time>=180 && time%180==0){ size++; }


if(time%250==0 && spellphase>=1 && time>=60){
let shot1=0;
let angle=rand(0,360);
	loop(28){
	CreateLaserA(shot1,GetX+1*cos(angle),GetY+1*sin(angle),500,10,23,50);
	if(phase%2==0){ SetLaserDataA(shot1,0,angle,laserspeed,0,0,0); }
	if(phase%2!=0){ SetLaserDataA(shot1,0,angle,-laserspeed,0,0,0); }
	SetShotKillTime(shot1,150);
	FireShot(shot1);
	angle+=360/28;
	}
phase++;
PlaySE(SElaserb2);
if(laserspeed<0.25){ laserspeed+=0.003; }
}


if((time+100)%200==0 && spellphase>=2 && time>=60){
let xsize=150;
let ysize=150;
let angle=GetAngleToPlayer+(360/14);
	loop(7){
		loop(2){
		effect1=(Obj_Create(OBJ_EFFECT));
		Obj_SetPosition(effect1,GetX,GetY);
		ObjEffect_SetScale(effect1,0,0); Obj_SetAngle(effect1,angle); Obj_SetSpeed(effect1,1);
		ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,GReffect); ObjEffect_SetRenderState(effect1,ADD);
		ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
		ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,0,0);
		ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,xsize,0);
		ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,0,ysize);
		ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,xsize,ysize);
		ObjEffect_SetVertexColor(effect1,0,255,255,255,255); ObjEffect_SetVertexColor(effect1,1,255,255,255,255);
		ObjEffect_SetVertexColor(effect1,2,255,255,255,255); ObjEffect_SetVertexColor(effect1,3,255,255,255,255);
		object1=object1~[effect1];
		timer1=timer1~[effect1];
		timer1[length(object1)-1]=0;
		size1=size1~[effect1];
		size1[length(object1)-1]=0;
		}
	angle+=360/7;
	}
PlaySE(SEshotb5);
}

let i=0;
while(i<length(object1)){
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); timer1=erase(timer1,i); size1=erase(size1,i);
	i--;
	}
	else{
	ObjEffect_SetScale(object1[i],size1[i],size1[i]);
	SetCollisionB(Obj_GetX(object1[i]),Obj_GetY(object1[i]),50*size1[i]);
	
	if(i%2==0){ ObjEffect_SetAngle(object1[i],0,0,timer1[i]*3); }
	if(i%2!=0){ ObjEffect_SetAngle(object1[i],0,0,-timer1[i]*3); }
	
	if(size1[i]<1){ size1[i]=size1[i]+0.05; }

	if(timer1[i]>=900){ Obj_Delete(object1[i]); }
	timer1[i]=timer1[i]+1;
	}
i++;
}


if(time>=600 && time%6==0 && spellphase>=3){
let angle=time*2;
	loop(3){
	CreateShot02(GetX,GetY-20,rand(4,6),angle+rand(-4,4),-0.08,rand(0.8,1.6),rand_int(97,106),0);
	CreateShot02(GetX,GetY-20,rand(4,6),-(angle*1.14)+rand(-4,4),-0.08,rand(0.8,1.6),rand_int(97,106),0);
	angle+=360/3;
	}
PlaySE(SEshots5);
usespell=-10;
}


if(time%600==0 && spellphase<3 && time>=60){
	SetColor(170,0,30);
	Concentration01(90);
	SetColor(255,255,255);
	PlaySE(SEcharge1);
}
if((time-90)%600==0 && spellphase<3 && time>=120){ spellphase++; }


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

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }
	
	SetGraphicRect(0,0,300,300);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG2);
	SetAlpha(bgfade/1.5);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0,0,300,300);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG1);
	SetAlpha(bgfade/4);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,-time/4);
	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{
	if(GotSpellCardBonus){ SetCommonData("LastTrumpCard",8); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}