script_enemy_main{

let shoot=220;
let distance=0;

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

let effect2=0;
let object2=[];
let timer2=[];
let scale2=[];

let effect1=0;
let shieldx=rand(GetClipMinX+50,GetClipMaxX-50);
let shieldy=rand(GetClipMinY+120,GetClipMaxY-50);
let shieldsize=0;
let extrashield=0;
let firstshield=true;

let character="Hotaru";
let cutin=character;
let dispelled=0;
let spellcards=3;
let spellcardnumber=22;
let damagerate=10;
let outfit=6;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=60;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEreflect1=("script\SoundEffects\reflect1.wav");
let SEexplodeb1=("script\SoundEffects\explodeb1.wav");
let SEfocus1=("script\SoundEffects\focus1.wav");

let GRspellcircle=("\script\Images\OtherEffects\SpellCircle1b.png");
let GRsafespot=("\script\Images\OtherEffects\SafeCircle1.png");

let BG1=("\script\Images\BackgroundLayers\Hotaru1.png");
let BG2=("\script\Images\BackgroundLayers\Hotaru2.png");
let GRboss=("\script\Images\CharacterSprites\Hotaru.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\ShotsHotaru1.txt");

	LoadSE("script\SoundEffects\reflect1.wav");
	LoadSE("script\SoundEffects\explodeb1.wav");
	LoadSE("script\SoundEffects\focus1.wav");

	LoadGraphic("\script\Images\OtherEffects\SpellCircle1b.png");
	LoadGraphic("\script\Images\OtherEffects\SafeCircle1.png");
	
	LoadGraphic("\script\Images\BackgroundLayers\Hotaru1.png");
	LoadGraphic("\script\Images\BackgroundLayers\Hotaru2.png");
	LoadGraphic("\script\Images\CharacterSprites\Hotaru.png");

	SetScore(250000);
	SetLife(350);
	SetTimer(45);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);

	SetX(GetCommonData("Boss2X"));
	SetY(GetCommonData("Boss2Y"));
	SetCommonData("Boss2Vanish",1);
	SetMovePosition02(cx,miny+100,50);

	SetCommonData("Boss1Move",3);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,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=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("Pyromania [Bomb Shelter] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

if(time%90==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);
	}
}


DeleteEnemyShotInCircle(SHOT,Obj_GetX(effect1),Obj_GetY(effect1),60+extrashield*shieldsize);
if(extrashield<20){ extrashield+=0.15; }

if(frame==shoot && GetTimer>0){
Obj_Delete(effect1);

let newshieldx=0;
let newshieldy=0;
let accepted=0;
	while(accepted==0){
	newshieldx=rand(minx+50,maxx-50);
	newshieldy=rand(miny+120,maxy-50);
	let xdistance=(((newshieldx-shieldx)^2+(0)^2)^0.5);
	let ydistance=(((0)^2+(newshieldy-shieldy)^2)^0.5);
		if((shieldx-50>newshieldx || shieldx+50<newshieldx) && (shieldy-50>newshieldy || shieldy+50<newshieldy)
		&& (shieldx-(175-distance)<newshieldx || shieldx+(175-distance)>newshieldx) && (shieldy-(175-distance)<newshieldy || shieldy+(175-distance)>newshieldy)){ accepted=1; }
	}
if(firstshield==true){ newshieldx=GetPlayerX; newshieldy=GetPlayerY; firstshield=false; }
shieldx=newshieldx;
shieldy=newshieldy;

let xsize=159;
let ysize=159;
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,shieldx,shieldy);
	ObjEffect_SetScale(effect1,1*shieldsize,1*shieldsize);
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,GRsafespot); ObjEffect_SetRenderState(effect1,ALPHA);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,xsize,0);
	ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,0,ysize);
	ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect1,0,200,255,255,255); ObjEffect_SetVertexColor(effect1,1,200,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,200,255,255,255); ObjEffect_SetVertexColor(effect1,3,200,255,255,255);

let angle=rand(-10,30);
	loop(6){
	let xsize=199;
	let ysize=199;
	effect2=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect2,rand(minx+30,maxx-30),rand(miny+30,maxy-30));
	Obj_SetPosition(effect2,GetX,GetY);
	ObjEffect_SetScale(effect2,0,0);
	Obj_SetSpeed(effect2,7+rand(4,7)*sin(angle)); Obj_SetAngle(effect2,angle);
	ObjEffect_SetLayer(effect2,1); ObjEffect_SetTexture(effect2,GRspellcircle); ObjEffect_SetRenderState(effect2,ADD);
	ObjEffect_SetPrimitiveType(effect2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect2,4);
	ObjEffect_SetVertexXY(effect2,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect2,0,0,0);
	ObjEffect_SetVertexXY(effect2,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect2,1,xsize,0);
	ObjEffect_SetVertexXY(effect2,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect2,2,0,ysize);
	ObjEffect_SetVertexXY(effect2,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect2,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect2,0,255,255,100,100); ObjEffect_SetVertexColor(effect2,1,255,255,100,100);
	ObjEffect_SetVertexColor(effect2,2,255,255,100,100); ObjEffect_SetVertexColor(effect2,3,255,255,100,100);
	object2=object2~[effect2];
	timer2=timer2~[effect2];
	timer2[length(object2)-1]=0;
	scale2=scale2~[effect2];
	scale2[length(object2)-1]=0;
	angle+=160/5;
	}
frame=0;
extrashield=0;
if(shoot>200){ shoot-=5; }
PlaySE(SEfocus1);
}

ObjEffect_SetAngle(effect1,0,0,time*5);
ObjEffect_SetScale(effect1,1*shieldsize,1*shieldsize);


if(frame==20){
let angle=rand(0,360);
let shot1=0;
	loop(6){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,Obj_GetX(effect1)+70*cos(angle),Obj_GetY(effect1)+70*sin(angle));
	Obj_SetAngle(shot1,angle+45);
	Obj_SetSpeed(shot1,0.5);
	ObjShot_SetDelay(shot1,20);
	ObjShot_SetGraphic(shot1,19);
if((((GetPlayerX-Obj_GetX(shot1))^2+(GetPlayerY-Obj_GetY(shot1))^2)^0.5)<40){ Obj_Delete(shot1); }
	angle+=360/6;
	}
angle+=360/12;
	loop(6){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,Obj_GetX(effect1)+70*cos(angle),Obj_GetY(effect1)+70*sin(angle));
	Obj_SetAngle(shot1,angle-45);
	Obj_SetSpeed(shot1,0.3);
	ObjShot_SetDelay(shot1,20);
	ObjShot_SetGraphic(shot1,20);
if((((GetPlayerX-Obj_GetX(shot1))^2+(GetPlayerY-Obj_GetY(shot1))^2)^0.5)<40){ Obj_Delete(shot1); }
	angle+=360/6;
	}
}


let i=0;
while(i<length(object2)){
	if(Obj_BeDeleted(object2[i])){
	object2=erase(object2,i); timer2=erase(timer2,i); scale2=erase(scale2,i);
	i--;
	}
	else{
	if(Obj_GetSpeed(object2[i])>0){ Obj_SetSpeed(object2[i],Obj_GetSpeed(object2[i])-0.3); }
	if(Obj_GetSpeed(object2[i])<0){ Obj_SetSpeed(object2[i],0); }
	ObjEffect_SetAngle(object2[i],0,0,-time*5);
	ObjEffect_SetScale(object2[i],scale2[i],scale2[i]);
	if(scale2[i]<0.3){ scale2[i]=scale2[i]+0.01; }
		if(frame==shoot-90){
		let shotx=0;
		CreateShotA(shotx,Obj_GetX(object2[i]),Obj_GetY(object2[i]),30);
		SetShotDataA(shotx,0,0,0,0,0,0,27);
		SetShotKillTime(shotx,0);
		FireShot(shotx);
		}
		if(frame==shoot-60){
		Explosion01(Obj_GetX(object2[i]),Obj_GetY(object2[i]),15,0.5,60);
			loop(300){
			CreateShot01(Obj_GetX(object2[i]),Obj_GetY(object2[i]),rand(8,13),rand(0,360),rand_int(25,26),0);
			}
		Obj_Delete(object2[i]);
		}
if((((Obj_GetX(effect1)-Obj_GetX(object2[i]))^2+(Obj_GetY(effect1)-Obj_GetY(object2[i]))^2)^0.5)<80 && timer2[i]>=30){ Obj_Delete(object2[i]); }
	timer2[i]=timer2[i]+1;
	}
i++;
}

if(frame==shoot-60 && time>=180){ PlaySE(SEexplodeb1); }
if(frame>=shoot-55 && frame<shoot-20 && time%rand_int(2,6)==0 && time>=180){ PlaySE(SEreflect1); }

if(frame<30 && shieldsize<30){ shieldsize+=1/30; }
if(frame>=shoot-30 && shieldsize>0){ shieldsize-=1/30; }


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss2X",GetX); SetCommonData("Boss2Y",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+time,300,300+time);
	SetGraphicScale(2+0.3*cos(time),2-0.3*cos(time));
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(180,180,180);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0-time,0-time/2,300-time,300-time/2);
	SetGraphicScale(2,2);
	SetTexture(BG2);
	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";
}

}