script_enemy_main{

let effect1=0;
let object1=[];
let timer1=[];
let size1=[];
let direction1=[];
let fade1=[];

let character="KurumiHotaru";
let cutin=character;
let dispelled=0;
let spellcards=2;
let spellcardnumber=24;
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 SEexplodes1=("script\SoundEffects\explodes1.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\explodes1.wav");

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

	SetScore(250000);
	SetLife(400);
	SetTimer(50);
	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("Boss2X"),GetCommonData("Boss2Y"),16);
SetShotAutoDeleteClip(32,32,32,32);

if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=7; }
if(GetCommonData("BombOn")==1 && GetPlayerY>maxy-100){ damagerate=4; }
SetDamageRate(damagerate,damagerate);

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("Intimidation [Firebreak] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


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


if(time==60){
SetCommonData("WarningX",cx-100);
SetCommonData("WarningSide",1);
SetCommonData("WarningTime",120);
SetCommonData("WarningSize",1);
SetCommonData("WarningType",2);
CreateEnemyFromFile("script\Functions\warnings.txt",0,0,0,0,0);
SetCommonData("WarningX",cx+100);
SetCommonData("WarningSide",1);
SetCommonData("WarningTime",120);
SetCommonData("WarningSize",1);
SetCommonData("WarningType",2);
CreateEnemyFromFile("script\Functions\warnings.txt",0,0,0,0,0);
SetCommonData("WarningX",cx-100);
SetCommonData("WarningSide",3);
SetCommonData("WarningTime",120);
SetCommonData("WarningSize",1);
SetCommonData("WarningType",2);
CreateEnemyFromFile("script\Functions\warnings.txt",0,0,0,0,0);
SetCommonData("WarningX",cx+100);
SetCommonData("WarningSide",3);
SetCommonData("WarningTime",120);
SetCommonData("WarningSize",1);
SetCommonData("WarningType",2);
CreateEnemyFromFile("script\Functions\warnings.txt",0,0,0,0,0);
}


if(time%8==0 && time>=150 && GetTimer>1){
let xpos=cx+180*cos(time*5+rand(-30,30));
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,xpos,miny-40+rand(-30,0));
	ObjEffect_SetScale(effect1,1,1);
	Obj_SetAngle(effect1,90);
	Obj_SetSpeed(effect1,1.5);
	ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,GReffect); ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-75,-75); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,75,-75); ObjEffect_SetVertexUV(effect1,1,150,0);
	ObjEffect_SetVertexXY(effect1,2,-75,75); ObjEffect_SetVertexUV(effect1,2,0,150);
	ObjEffect_SetVertexXY(effect1,3,75,75); ObjEffect_SetVertexUV(effect1,3,150,150);
	ObjEffect_SetVertexColor(effect1,0,255,255,255,255); ObjEffect_SetVertexColor(effect1,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,255,255,255,255); ObjEffect_SetVertexColor(effect1,3,255,255,255,255);
	object1=object1~[effect1];
	timer1=timer1~[effect1];
	timer1[length(object1)-1]=0;
	size1=size1~[effect1];
	size1[length(object1)-1]=1;
	direction1=direction1~[effect1];
	direction1[length(object1)-1]=rand_int(0,1);
	fade1=fade1~[effect1];
	fade1[length(object1)-1]=255;
let xpos=cx+180*cos(180+(time*5)+rand(-30,30));
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,xpos,maxy+40+rand(30,0));
	ObjEffect_SetScale(effect1,1,1);
	Obj_SetAngle(effect1,270);
	Obj_SetSpeed(effect1,1.5);
	ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,GReffect); ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-75,-75); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,75,-75); ObjEffect_SetVertexUV(effect1,1,150,0);
	ObjEffect_SetVertexXY(effect1,2,-75,75); ObjEffect_SetVertexUV(effect1,2,0,150);
	ObjEffect_SetVertexXY(effect1,3,75,75); ObjEffect_SetVertexUV(effect1,3,150,150);
	ObjEffect_SetVertexColor(effect1,0,255,255,255,255); ObjEffect_SetVertexColor(effect1,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,255,255,255,255); ObjEffect_SetVertexColor(effect1,3,255,255,255,255);
	object1=object1~[effect1];
	timer1=timer1~[effect1];
	timer1[length(object1)-1]=0;
	size1=size1~[effect1];
	size1[length(object1)-1]=1;
	direction1=direction1~[effect1];
	direction1[length(object1)-1]=rand_int(0,1);
	fade1=fade1~[effect1];
	fade1[length(object1)-1]=255;
if(time%16==0){ PlaySE(SEexplodes1); }
}

let i=0;
while(i<length(object1)){
	timer1[i]=timer1[i]+1;
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); timer1=erase(timer1,i); size1=erase(size1,i); direction1=erase(direction1,i); fade1=erase(fade1,i);
	i--;
	}
	else{
	if(size1[i]>0.1){ SetCollisionB(Obj_GetX(object1[i]),Obj_GetY(object1[i]),size1[i]*50); }
	if(size1[i]<=0.2){
		if(fade1[i]>0){ fade1[i]=fade1[i]-7; }
		ObjEffect_SetVertexColor(object1[i],0,fade1[i],255,255,255); ObjEffect_SetVertexColor(object1[i],1,fade1[i],255,255,255);
		ObjEffect_SetVertexColor(object1[i],2,fade1[i],255,255,255); ObjEffect_SetVertexColor(object1[i],3,fade1[i],255,255,255);
	}
	ObjEffect_SetScale(object1[i],size1[i],size1[i]);
	if(direction1[i]==0){ ObjEffect_SetAngle(object1[i],0,0,timer1[i]*2); }
	if(direction1[i]==1){ ObjEffect_SetAngle(object1[i],0,0,-timer1[i]*2); }
		if(fade1[i]<=0 || size1[i]<=0.05){
			if(GetTimer>=1){ CreateShot01(Obj_GetX(object1[i]),Obj_GetY(object1[i]),0.8,rand(0,360),30,20); }
		Obj_Delete(object1[i]);
		}
	if(GetTimer>=1){ size1[i]=size1[i]-0.004; }
	if(GetTimer<1 && size1[i]>0){ size1[i]=size1[i]-0.015; }
	if(GetLife<4){ Obj_Delete(object1[i]); SetLife(0); }
	timer1[i]=timer1[i]+1;
	}
i++;
}

time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }

#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,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);
}

@DrawLoop{
}

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

}