script_enemy_main{

let maxspeed=7;
let bgspin=rand(0,360);
let bgspinslowdown=maxspeed;
let bgstopped=1;
let radius=340;
let color=rand_int(0,9);

let character="Tomomi";
let cutin=character;
let dispelled=0;
let spellcards=3;
let spellcardnumber=31;
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 SElaserb2=("script\SoundEffects\laserb2.wav");
let SEshots3=("script\SoundEffects\shots3.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\laserb2.wav");
	LoadSE("script\SoundEffects\shots3.wav");

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

	SetScore(300000);
	SetLife(450);
	SetTimer(50);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+140,50);

	SetCommonData("Spin",0);
	SetCommonData("SpinSpeed",0);
}
	
@MainLoop{

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

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=6; }
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("Roulette [Monte Carlo Fallacy] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

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


if(time==100){
let angle=rand(0,360);
	loop(6){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Tomomi - Monte Carlo Fallacy - Familiar.txt",GetX,GetY,0,0,[angle,1]);
	angle+=360/12;
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Tomomi - Monte Carlo Fallacy - Familiar.txt",GetX,GetY,0,0,[angle,7]);
	angle+=360/12;
	}
}

bgspin+=maxspeed-bgspinslowdown;
if(bgspinslowdown<maxspeed){ bgspinslowdown+=0.02; }

if(bgspinslowdown>=maxspeed && time>=120){
bgspinslowdown=rand(maxspeed,maxspeed-0.5);
bgstopped=1;
let shot1=0;
	CreateLaserA(shot1,cx+155*cos(bgspin-90),cy+155*sin(bgspin-90),500,30,101,60);
	SetLaserDataA(shot1,0,bgspin-90+180,0,0,0,0);
	SetShotKillTime(shot1,120);
	FireShot(shot1);
	CreateLaserA(shot1,cx+155*cos(bgspin-90),cy+155*sin(bgspin-90),500,20,101,60);
	SetLaserDataA(shot1,0,bgspin-55+180,0,0,0,0);
	SetShotKillTime(shot1,120);
	FireShot(shot1);
	CreateLaserA(shot1,cx+155*cos(bgspin-90),cy+155*sin(bgspin-90),500,20,101,60);
	SetLaserDataA(shot1,0,bgspin-125+180,0,0,0,0);
	SetShotKillTime(shot1,120);
	FireShot(shot1);
usespell=-120;
PlaySE(SElaserb2);
}

SetCommonData("Spin",bgspin);
SetCommonData("SpinSpeed",bgspinslowdown);
if(bgstopped==1){ bgspinslowdown-=0.4; }
if(bgspinslowdown<=0){ frame=0; bgstopped=0; }


if(time>=60){
	loop(5){
	let angle=rand(0,360);
	let randomradius=rand(0,90);
	let shot1=0;
	CreateShotA(shot1,cx+(radius+randomradius)*cos(angle),cy+(radius+randomradius)*sin(angle),20);
	SetShotDataA(shot1,0,3,angle+180,0,-0.07,0,25+color);
	SetShotKillTime(shot1,60);
	FireShot(shot1);
	}
if(radius>220){ radius--; }
if(time%30==0){ color--; }
if(color<0){ color=9; }
if(time%5==0){ PlaySE(SEshots3); }
}


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

@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,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}