script_enemy_main{

let angle=0;
let radius=0;
let shotcount=0;
let position=0;
let size=0;
let speed=2;

let bgspin=rand(0,360);
let bgspinslowdown=0;
let bgstopped=0;

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

let character="Tomomi";
let cutin=character;
let spellcards=6;
let spellcardnumber=52;
let dispelled=0;
let damagerate=10;
let outfit=5;
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 SEshotm6=("\script\SoundEffects\shotm6.wav");

let BG1=("\script\Images\BackgroundLayers\Tomomi3.png");
let BG2=("\script\Images\BackgroundLayers\Tomomi1.png");
let GRboss=("\script\Images\CharacterSprites\Tomomi.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\ShotsTomomi1.txt");
	
	LoadSE("\script\SoundEffects\shotm6.wav");

	LoadGraphic("\script\Images\BackgroundLayers\Tomomi3.png");
	LoadGraphic("\script\Images\BackgroundLayers\Tomomi1.png");
	LoadGraphic("\script\Images\CharacterSprites\Tomomi.png");

	SetScore(750000);
	SetLife(400);
	SetTimer(60);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	
	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetMovePosition02(cx,miny+120,50);

	SetCommonData("Boss1Vanish",1);
}
	
@MainLoop{

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

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=2.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("Gambler's Fallacy [Red Snake Roulette Bet]",spellcardnumber); 
HealthBar();
Portrait(cutin,2);

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


if(frame==60){
angle=GetAngleToPlayer;
size=(((GetPlayerX-GetX)^2+(GetPlayerY-GetY)^2)^0.5)/14;
}

if(frame%5==0 && frame>=60 && shotcount<12){
let radius2=0;
if(shotcount==0 || shotcount==5 || shotcount==6 || shotcount==11){ position=-90; radius2=size*2; }
if(shotcount==1 || shotcount== 4 || shotcount==7 || shotcount==10){ position=0; radius2=0; }
if(shotcount==2 || shotcount==3 || shotcount==8 || shotcount==9){ position=90; radius2=size*2; }
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+radius*cos(angle)+radius2*cos(angle-position),GetY+radius*sin(angle)+radius2*sin(angle-position));
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetDelay(shot1,30);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,157);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
radius+=size;
shotcount++;
}

if(shotcount==12){ frame=-60; radius=0; shotcount=0; }


if(time>=60){
let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); timer1=erase(timer1,i);
		i--;
		}
		else{
		if(timer1[i]==29){
			CreateEnemyFromFile(GetCurrentScriptDirectory~"Tomomi - Red Snake Roulette Bet - Familiar.txt",Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,0,speed);
			AddLife(-1); 
			Obj_Delete(bullet1[i]);
			PlaySE(SEshotm6);
			}
		timer1[i]=timer1[i]+1;
		}
	i++;
	}
}

if(GetCommonDataDefault("FamiliarDestroyed",0)==1 && OnBomb==false){ AddLife(-10); SetCommonData("FamiliarDestroyed",0); }
if(GetCommonDataDefault("FamiliarDestroyed",0)==1 && OnBomb==true){ SetCommonData("FamiliarDestroyed",0); }


bgspin+=10-bgspinslowdown;
if(bgspinslowdown<10){ bgspinslowdown+=0.04; }
if(bgspinslowdown>=10){ bgstopped=1; }
if(bgstopped==1){ bgspinslowdown-=0.4; }
if(bgspinslowdown<=0){ bgstopped=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<255){ bgfade+=5; }

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(2,2);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(150,150,150);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,-time/4);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,400,400);
	SetGraphicScale(1,1);
	SetTexture(BG2);
	SetGraphicAngle(0,0,bgspin);
	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,5);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}