script_enemy_main{

let direction=0;
let xpos=0;
let ypos=0;
let newxpos=0;
let newypos=0;

let shot1=0;
let bullet1=[];
let timer1=[];
let radius1=[];
let angle1=[];
let size1=[];
let speed1=[];

let character="KurumiHotaru";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=25;
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 SEfire1=("script\SoundEffects\fire1.wav");

let GReffect=("\script\Images\OtherEffects\SunBullet.png");
let BG1=("\script\Images\BackgroundLayers\Hotaru1.png");
let BG2=("\script\Images\BackgroundLayers\Kurumi1.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\ShotsKurumiHotaru1.txt");

	LoadSE("script\SoundEffects\fire1.wav");
	LoadSE("script\SoundEffects\shotm8.wav");

	LoadGraphic("\script\Images\OtherEffects\SunBullet.png");
	LoadGraphic("\script\Images\BackgroundLayers\Hotaru1.png");
	LoadGraphic("\script\Images\BackgroundLayers\Kurumi1.png");

	SetScore(500000);
	SetLife(400);
	SetTimer(60);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	MagicCircle(false);
	SetX(cx);
	SetY(miny-1000);

	SetCommonData("UseSpell1",0);
	SetCommonData("UseSpell2",0);
}
	
@MainLoop{

SetCollisionA(GetCommonData("Boss1X"),GetCommonData("Boss1Y"),16);
SetCollisionA(GetCommonData("Boss2X"),GetCommonData("Boss2Y"),16);
SetCollisionB(GetCommonData("Boss1X"),GetCommonData("Boss1Y"),16);
SetCollisionB(GetCommonData("Boss2X"),GetCommonData("Boss2Y"),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=5; }
if(GetCommonData("BombOn")==1 && GetPlayerY>maxy-100){ 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("Pressure [Fire Whirl] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


if(time==0){
CreateEnemyFromFile((GetCurrentScriptDirectory~"Kurumi-Hotaru - Fire Whirl - Kurumi.txt"),GetCommonData("Boss1X"),GetCommonData("Boss1Y"),0,0,0);
CreateEnemyFromFile((GetCurrentScriptDirectory~"Kurumi-Hotaru - Fire Whirl - Hotaru.txt"),GetCommonData("Boss2X"),GetCommonData("Boss2Y"),0,0,0);
}

if(time==45){ CreateEnemyFromFile(("script\Functions\spellcardwarning.txt"),0,0,0,0,0); }


if(time>=90 && time<180 && time%2==0){
	let radius=rand(30,45);
	let angle=(time*40)+rand(-60,60);
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetPlayerX+radius*cos(angle),GetPlayerY+radius*sin(angle));
	Obj_SetAngle(shot1,angle);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,rand_int(1,3));
	ObjShot_SetDelay(shot1,15);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	radius1=radius1~[shot1];
	radius1[length(bullet1)-1]=radius;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	size1=size1~[shot1];
	size1[length(bullet1)-1]=1;
	speed1=speed1~[shot1];
	speed1[length(bullet1)-1]=rand(0,2);
}

if(time==90){xpos=GetPlayerX; ypos=GetPlayerY; newxpos=GetPlayerX; newypos=GetPlayerY; }
if((time+0)%1400==0 && time>=350){ newxpos=cx-rand(90,60); newypos=cy+rand(0,30); }
if((time+350)%1400==0){ newxpos=cx+rand(90,60); newypos=cy+rand(0,30); }
if((time+700)%1400==0){ newxpos=cx-rand(90,60); newypos=cy+rand(120,90); }
if((time+1050)%1400==0){ newxpos=cx+rand(90,60); newypos=cy+rand(120,90); }
let angle=atan2(newypos-ypos,newxpos-xpos);
let speed=0.8;
xpos+=speed*cos(angle);
ypos+=speed*sin(angle);



let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i); radius1=erase(radius1,i);
	size1=erase(size1,i); speed1=erase(speed1,i); 
	i--;
	}
	else{

	if(timer1[i]<25){ size1[i]=size1[i]+(25-(timer1[i]))/100; }
	if(timer1[i]>=15 && timer1[i]<140){ speed1[i]=speed1[i]+0.04; }
	if(timer1[i]>=60 && size1[i]>(2.7+(radius1[i]/300))){ size1[i]=size1[i]-0.02; }

	Obj_SetPosition(bullet1[i],xpos+(radius1[i]*size1[i])*cos(angle1[i]),ypos+(radius1[i]*size1[i])*sin(angle1[i]));
	Obj_SetAngle(bullet1[i],angle1[i]+90);
	
	if(timer1[i]>=90 && timer1[i]%3==0){
	let shotx=0;
	let radius=rand(-7,7);
	CreateShotA(shotx,Obj_GetX(bullet1[i])+radius*cos(Obj_GetAngle(bullet1[i])),Obj_GetY(bullet1[i])+radius*sin(Obj_GetAngle(bullet1[i])),10);
	SetShotDataA(shotx,0,rand(5,7),Obj_GetAngle(bullet1[i])+rand(0,20),rand(1,2),-0.25,0,rand_int(1,3));
	SetShotKillTime(shotx,rand_int(15,20));
	FireShot(shotx);
	}
	
	if(timer1[i]>=150 && timer1[i]%2==0){
	let shotx=0;
	let radius=rand(-7,7);
	CreateShotA(shotx,Obj_GetX(bullet1[i])+radius*cos(Obj_GetAngle(bullet1[i])),Obj_GetY(bullet1[i])+radius*sin(Obj_GetAngle(bullet1[i])),10);
	SetShotDataA(shotx,0,rand(5,7),Obj_GetAngle(bullet1[i])+rand(0,20),rand(1,2),0,0,rand_int(1,3));
	SetShotKillTime(shotx,rand_int(40,60));
	FireShot(shotx);
	}
	
	angle1[i]=angle1[i]+(speed1[i]+(radius1[i]/20));
	size1[i]=size1[i]-0.0005;
	
	timer1[i]=timer1[i]+1;
	}
i++;
}

if(time>=90 && time<180 && time%12==0){ PlaySE(SEfire1); }
if(time>=270 && time%6==0){ PlaySE(SEfire1); }



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

	SetTexture(BG1); SetColor(180,180,180); SetRenderState(ALPHA);
	
	SetGraphicRect(0,0+(time*2),600,600+(time*2)); SetGraphicScale(2+0.3*cos(time),2-0.3*cos(time));
	SetAlpha(bgfade/3); SetGraphicAngle(0,0,time*2); DrawGraphic(cx+40*cos(time*2),cy);
	
	SetGraphicRect(0,0+(time*1.5),600,600+(time*1.5)); SetGraphicScale(2+0.3*cos(time+120),2-0.3*cos(time+120));
	SetAlpha(bgfade/3); SetGraphicAngle(0,0,-time*1.5); DrawGraphic(cx,cy+30*sin(time*2.5));
	
	SetGraphicRect(0+(time*2),0,600+(time*2),600); SetGraphicScale(2+0.3*cos(time+240),2-0.3*cos(time+240));
	SetAlpha(bgfade/3); SetGraphicAngle(0,0,time*1.5); DrawGraphic(cx+40*cos(time*1.5),cy+20*sin(time*2.5));
	
	SetGraphicRect(0,0,50,1200);
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetColor(255,180,150);
	SetRenderState(ALPHA);
	SetGraphicScale(0.6,0.6); SetGraphicAngle(0,0,-10); DrawGraphic(cx-100,cy);
	SetGraphicScale(0.7,0.7); SetGraphicAngle(0,0,30); DrawGraphic(cx-100,cy);
	SetGraphicScale(0.8,0.8); SetGraphicAngle(0,0,70); DrawGraphic(cx+100,cy);
	SetGraphicScale(0.9,0.9); SetGraphicAngle(0,0,120); DrawGraphic(cx-40,cy);
	SetGraphicScale(1,1); SetGraphicAngle(0,0,160); DrawGraphic(cx+120,cy);
	SetGraphicScale(1.1,1.1); SetGraphicAngle(0,0,10); DrawGraphic(cx+70,cy);
	SetGraphicScale(1.2,1.2); SetGraphicAngle(0,0,100); DrawGraphic(cx,cy+150);
	SetGraphicScale(1.3,1.3); SetGraphicAngle(0,0,80); DrawGraphic(cx,cy-150);
	
	SetTexture(BG1); SetColor(180,180,180); SetRenderState(ALPHA);
	SetGraphicRect(0+(time*2),0,600+(time*2),600); SetGraphicScale(2+0.3*cos(time+240),2-0.3*cos(time+240));
	SetAlpha(bgfade/3); SetGraphicAngle(0,0,time*1.5); DrawGraphic(cx+40*cos(time*1.5),cy+20*sin(time*2.5));
	
}

@DrawLoop{
}

@Finalize{
	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}