script_enemy_main{

let color=255;
let phase=0;
let speed=0;

let character="Takeo";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=80;
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 SEshots5=("script\SoundEffects\shots5.wav");
let SEshotb1=("script\SoundEffects\shotb1.wav");
let SEspawn2=("script\SoundEffects\spawn2.wav");

let BG1=("\script\Images\BackgroundLayers\Takeo1b.png");
let BG2=("\script\Images\BackgroundLayers\Takeo3.png");
let GRboss=("\script\Images\CharacterSprites\Takeo.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\ShotsTakeo1.txt");

	LoadSE("script\SoundEffects\shots5.wav");
	LoadSE("script\SoundEffects\shotb1.wav");
	LoadSE("script\SoundEffects\spawn2.wav");
	
	LoadGraphic("\script\Images\BackgroundLayers\Takeo1b.png");
	LoadGraphic("\script\Images\BackgroundLayers\Takeo3.png");
	LoadGraphic("\script\Images\CharacterSprites\Takeo.png");

	SetScore(500000);
	SetLife(200);
	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+80,50);

	SetDurableSpellCard;
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(24,24,24,24);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; if(GetCommonData("PlayerType")==5){ damagerate=5; } }
if(GetCommonData("BombOn")==1){ damagerate=0; }
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("Tatehaya Susanoo No Mikoto [Kusanagi No Tsurugi]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

if((frame==180 || frame==380) && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+80,miny+100),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+80,miny+100),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+80,miny+100),1.5);
	}
}


if(frame==60){
let angle=GetAngleToPlayer-(25*3.5);
	loop(8){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Takeo - Kusanagi No Tsurugi - Familiar.txt",GetX,GetY-15,0,0,angle);
	angle+=25;
	}
PlaySE(SEspawn2);
}


if(phase%2!=0){
	if(frame>=120 && frame<=180 && time%4==0){
	SetShotColor(color,color,color);
	let angle=90;
		loop(60){
		CreateShot01(GetX,GetY-15,7-speed,angle,72,0);
		angle+=360/60;
		}
	speed+=0.3;
	color-=7;
	if(time%8==0){ PlaySE(SEshotb1); }
	}
SetShotColor(255,255,255);
}

if(phase%2==0){
	SetShotColor(color,color,color);
	if(frame>=120 && frame<270 && time%8==0){
	let angle=GetAngleToPlayer-(25*3.5);
		loop(8){
		CreateShot01(GetX,GetY-15,5.5,angle,71,0);
		angle+=25;
		}
	color-=3;
	PlaySE(SEshots5);
	usespell=15;
	}
	if(frame>=120 && frame<270 && time%16==0){
	let angle=GetAngleToPlayer-(25*3.5);
	angle+=12.5;
		loop(7){
		CreateShot01(GetX,GetY-15,4,angle,71,0);
		angle+=25;
		}
	color-=3;
	}
	if(frame>=120 && frame<270 && time%24==0){
	let angle=GetAngleToPlayer-(25*3.5);
	angle+=6.25;
		loop(14){
		CreateShot01(GetX,GetY-15,2.5,angle,71,0);
		angle+=12.5;
		}
	color-=3;
	}
SetShotColor(255,255,255);
}

if(frame==430){ frame=0; color=255; speed=0; phase++; }

if(GetCommonDataDefault("FamiliarDestroyed",0)==1){ AddLife(-5); SetCommonData("FamiliarDestroyed",0); }



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<180){ bgfade+=5; }
	
	SetGraphicRect(0,0,280,300);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0,0-time/2,528,592-time/2);
	SetGraphicScale(1,1);
	SetColor(40,0,40);
	SetTexture(BG1);
	SetAlpha(bgfade);
	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",13); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
	if(BeVanished==false){ DeleteEnemyShot(CHILD); }
}

}