script_enemy_main{

let shot1=0;
let bullet1=[];
let angle=rand(0,360);
let radius=0;

let character="Tomoko";
let spellcards=6;
if(GetCommonData("Difficulty")>=2){ spellcards=7; }
let dispelled=0;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=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 SEshots4=("\script\SoundEffects\shots4.wav");
let SEmagics1=("\script\SoundEffects\magics1.wav");

let GRboss=("\script\Images\CharacterSprites\Tomoko.png");

#include_function "script/Functions/HealthBarLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsTomoko1.txt");

	LoadSE("\script\SoundEffects\shots4.wav");
	LoadSE("\script\SoundEffects\magics1.wav");

	LoadGraphic("\script\Images\CharacterSprites\Tomoko.png");

	SetLife(250);
	SetTimer(30);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);
	
	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetCommonData("Boss1Vanish",1);

	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

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

let weaken=1;
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=5; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

HealthBar();

if(time%200==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(GetCommonData("Difficulty")==1){

if(time==60){
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,9);
	bullet1=bullet1~[shot1];
	}
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,10);
	bullet1=bullet1~[shot1];
	}
PlaySE(SEmagics1);
usespell=-30;
}

if(time>=60){
	Obj_SetPosition(bullet1[0],GetX+(radius*10)*cos(time+0),GetY+(radius*4)*sin(time+0));
	Obj_SetPosition(bullet1[1],GetX+(radius*10)*cos(time+120),GetY+(radius*4)*sin(time+120));
	Obj_SetPosition(bullet1[2],GetX+(radius*10)*cos(time+240),GetY+(radius*4)*sin(time+240));

	Obj_SetAngle(bullet1[0],time+90);
	Obj_SetAngle(bullet1[1],time+210);
	Obj_SetAngle(bullet1[2],time+330);

	Obj_SetPosition(bullet1[3],GetX-(radius*7)*cos(time+0),GetY+(radius*2)*sin(time+0));
	Obj_SetPosition(bullet1[4],GetX-(radius*7)*cos(time+120),GetY+(radius*2)*sin(time+120));
	Obj_SetPosition(bullet1[5],GetX-(radius*7)*cos(time+240),GetY+(radius*2)*sin(time+240));

	Obj_SetAngle(bullet1[3],-time+90);
	Obj_SetAngle(bullet1[4],-time+330);
	Obj_SetAngle(bullet1[5],-time+210);
angle+=2;
}

if(time%5==0 && time>=90){
let startspeed=10;
let speed=2.2;
let color=255;
	loop(2){
	SetShotColor(color,color,color);
	CreateShot02(Obj_GetX(bullet1[0]),Obj_GetY(bullet1[0]),startspeed,angle+(speed*2),-0.3,speed,57,25);
	CreateShot02(Obj_GetX(bullet1[1]),Obj_GetY(bullet1[1]),startspeed,angle+120+(speed*2),-0.3,speed,57,25);
	CreateShot02(Obj_GetX(bullet1[2]),Obj_GetY(bullet1[2]),startspeed,angle+240+(speed*2),-0.3,speed,57,25);

	CreateShot02(Obj_GetX(bullet1[3]),Obj_GetY(bullet1[3]),startspeed,-angle+245-(speed*2),-0.3,speed,58,25);
	CreateShot02(Obj_GetX(bullet1[4]),Obj_GetY(bullet1[4]),startspeed,-angle+125-(speed*2),-0.3,speed,58,25);
	CreateShot02(Obj_GetX(bullet1[5]),Obj_GetY(bullet1[5]),startspeed,-angle+5-(speed*2),-0.3,speed,58,25);
	startspeed-=0.7;
	speed-=0.7;
	color-=50;
	}
SetShotColor(255,255,255);
usespell=10;
}
if(time%5==0 && time>=90){ PlaySE(SEshots4); }

if(time>=60 && radius<10){ radius+=0.3; }

} //Easy

//=============================================================================================================

if(GetCommonData("Difficulty")==2){

if(time==60){
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,9);
	bullet1=bullet1~[shot1];
	}
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,10);
	bullet1=bullet1~[shot1];
	}
PlaySE(SEmagics1);
usespell=-30;
}

if(time>=60){
	Obj_SetPosition(bullet1[0],GetX+(radius*10)*cos(time+0),GetY+(radius*4)*sin(time+0));
	Obj_SetPosition(bullet1[1],GetX+(radius*10)*cos(time+120),GetY+(radius*4)*sin(time+120));
	Obj_SetPosition(bullet1[2],GetX+(radius*10)*cos(time+240),GetY+(radius*4)*sin(time+240));

	Obj_SetAngle(bullet1[0],time+90);
	Obj_SetAngle(bullet1[1],time+210);
	Obj_SetAngle(bullet1[2],time+330);

	Obj_SetPosition(bullet1[3],GetX-(radius*7)*cos(time+0),GetY+(radius*2)*sin(time+0));
	Obj_SetPosition(bullet1[4],GetX-(radius*7)*cos(time+120),GetY+(radius*2)*sin(time+120));
	Obj_SetPosition(bullet1[5],GetX-(radius*7)*cos(time+240),GetY+(radius*2)*sin(time+240));

	Obj_SetAngle(bullet1[3],-time+90);
	Obj_SetAngle(bullet1[4],-time+330);
	Obj_SetAngle(bullet1[5],-time+210);
angle+=3;
}

if(time%4==0 && time>=90){
let startspeed=10;
let speed=2.2;
let color=255;
	loop(3){
	SetShotColor(color,color,color);
	CreateShot02(Obj_GetX(bullet1[0]),Obj_GetY(bullet1[0]),startspeed,angle+(speed*2),-0.3,speed,57,25);
	CreateShot02(Obj_GetX(bullet1[1]),Obj_GetY(bullet1[1]),startspeed,angle+120+(speed*2),-0.3,speed,57,25);
	CreateShot02(Obj_GetX(bullet1[2]),Obj_GetY(bullet1[2]),startspeed,angle+240+(speed*2),-0.3,speed,57,25);

	CreateShot02(Obj_GetX(bullet1[3]),Obj_GetY(bullet1[3]),startspeed,-angle+245-(speed*2),-0.3,speed,58,25);
	CreateShot02(Obj_GetX(bullet1[4]),Obj_GetY(bullet1[4]),startspeed,-angle+125-(speed*2),-0.3,speed,58,25);
	CreateShot02(Obj_GetX(bullet1[5]),Obj_GetY(bullet1[5]),startspeed,-angle+5-(speed*2),-0.3,speed,58,25);
	startspeed-=0.4;
	speed-=0.4;
	color-=50;
	}
SetShotColor(255,255,255);
usespell=10;
}
if(time%5==0 && time>=90){ PlaySE(SEshots4); }

if(time>=60 && radius<10){ radius+=0.3; }

} //Normal

//=============================================================================================================

if(GetCommonData("Difficulty")==3){

if(time==60){
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,9);
	bullet1=bullet1~[shot1];
	}
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,10);
	bullet1=bullet1~[shot1];
	}
PlaySE(SEmagics1);
usespell=-30;
}

if(time>=60){
	Obj_SetPosition(bullet1[0],GetX+(radius*10)*cos(time+0),GetY+(radius*4)*sin(time+0));
	Obj_SetPosition(bullet1[1],GetX+(radius*10)*cos(time+120),GetY+(radius*4)*sin(time+120));
	Obj_SetPosition(bullet1[2],GetX+(radius*10)*cos(time+240),GetY+(radius*4)*sin(time+240));

	Obj_SetAngle(bullet1[0],time+90);
	Obj_SetAngle(bullet1[1],time+210);
	Obj_SetAngle(bullet1[2],time+330);

	Obj_SetPosition(bullet1[3],GetX-(radius*7)*cos(time+0),GetY+(radius*2)*sin(time+0));
	Obj_SetPosition(bullet1[4],GetX-(radius*7)*cos(time+120),GetY+(radius*2)*sin(time+120));
	Obj_SetPosition(bullet1[5],GetX-(radius*7)*cos(time+240),GetY+(radius*2)*sin(time+240));

	Obj_SetAngle(bullet1[3],-time+90);
	Obj_SetAngle(bullet1[4],-time+330);
	Obj_SetAngle(bullet1[5],-time+210);
angle+=2;
}

if(time%4==0 && time>=90){
let startspeed=10;
let speed=2.5;
let color=255;
	loop(3){
	SetShotColor(color,color,color);
	CreateShot02(Obj_GetX(bullet1[0]),Obj_GetY(bullet1[0]),startspeed,angle+(speed*2),-0.3,speed,57,25);
	CreateShot02(Obj_GetX(bullet1[1]),Obj_GetY(bullet1[1]),startspeed,angle+120+(speed*2),-0.3,speed,57,25);
	CreateShot02(Obj_GetX(bullet1[2]),Obj_GetY(bullet1[2]),startspeed,angle+240+(speed*2),-0.3,speed,57,25);

	CreateShot02(Obj_GetX(bullet1[3]),Obj_GetY(bullet1[3]),startspeed,-angle+245-(speed*2),-0.3,speed,58,25);
	CreateShot02(Obj_GetX(bullet1[4]),Obj_GetY(bullet1[4]),startspeed,-angle+125-(speed*2),-0.3,speed,58,25);
	CreateShot02(Obj_GetX(bullet1[5]),Obj_GetY(bullet1[5]),startspeed,-angle+5-(speed*2),-0.3,speed,58,25);
	startspeed-=0.6;
	speed-=0.7;
	color-=50;
	}
SetShotColor(255,255,255);
usespell=10;
}
if(time%4==0 && time>=90){ PlaySE(SEshots4); }

if(time>=60 && radius<10){ radius+=0.3; }

} //Hard

//=============================================================================================================

if(GetCommonData("Difficulty")==4){
if(time==60){
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,9);
	bullet1=bullet1~[shot1];
	}
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,10);
	bullet1=bullet1~[shot1];
	}
PlaySE(SEmagics1);
usespell=-30;
}

if(time>=60){
	Obj_SetPosition(bullet1[0],GetX+(radius*10)*cos(time+0),GetY+(radius*4)*sin(time+0));
	Obj_SetPosition(bullet1[1],GetX+(radius*10)*cos(time+120),GetY+(radius*4)*sin(time+120));
	Obj_SetPosition(bullet1[2],GetX+(radius*10)*cos(time+240),GetY+(radius*4)*sin(time+240));

	Obj_SetAngle(bullet1[0],time+90);
	Obj_SetAngle(bullet1[1],time+210);
	Obj_SetAngle(bullet1[2],time+330);

	Obj_SetPosition(bullet1[3],GetX-(radius*7)*cos(time+0),GetY+(radius*2)*sin(time+0));
	Obj_SetPosition(bullet1[4],GetX-(radius*7)*cos(time+120),GetY+(radius*2)*sin(time+120));
	Obj_SetPosition(bullet1[5],GetX-(radius*7)*cos(time+240),GetY+(radius*2)*sin(time+240));

	Obj_SetAngle(bullet1[3],-time+90);
	Obj_SetAngle(bullet1[4],-time+330);
	Obj_SetAngle(bullet1[5],-time+210);
angle+=4;
}

if(time%3==0 && time>=90){
let startspeed=10;
let speed=2.5;
let color=255;
	loop(3){
	SetShotColor(color,color,color);
	CreateShot02(Obj_GetX(bullet1[0]),Obj_GetY(bullet1[0]),startspeed,angle+(speed*3),-0.3,speed,57,25);
	CreateShot02(Obj_GetX(bullet1[1]),Obj_GetY(bullet1[1]),startspeed,angle+120+(speed*3),-0.3,speed,57,25);
	CreateShot02(Obj_GetX(bullet1[2]),Obj_GetY(bullet1[2]),startspeed,angle+240+(speed*3),-0.3,speed,57,25);

	CreateShot02(Obj_GetX(bullet1[3]),Obj_GetY(bullet1[3]),startspeed,-angle+245-(speed*3),-0.3,speed,58,25);
	CreateShot02(Obj_GetX(bullet1[4]),Obj_GetY(bullet1[4]),startspeed,-angle+125-(speed*3),-0.3,speed,58,25);
	CreateShot02(Obj_GetX(bullet1[5]),Obj_GetY(bullet1[5]),startspeed,-angle+5-(speed*3),-0.3,speed,58,25);
	startspeed-=0.5;
	speed-=0.6;
	color-=50;
	}
SetShotColor(255,255,255);
usespell=10;
}
if(time%4==0 && time>=90){ PlaySE(SEshots4); }

if(time>=60 && radius<10){ radius+=0.3; }

} //Lunatic


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/HealthBar.txt";
}

@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); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}
 
@Finalize{
}

}