script_enemy_main{

let effect3=0;
let scale=0;
let angle=-5;

let effect1=0;
let object1=[];
let timer1=[];
let angle1=[];

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

let character="Haruna";
let cutin=character;
let spellcards=2;
let spellcardnumber=34;
let dispelled=0;
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 SElaserm2=("\script\SoundEffects\laserm2.wav");

let GReffect1=("\script\Images\OtherEffects\Pulse.png");
let GReffect2=("\script\Images\OtherEffects\BlackBlur.png");

let BG1=("\script\Images\BackgroundLayers\Haruna2.png");
let BG2=("\script\Images\BackgroundLayers\Haruna3a.png");
let GRboss=("\script\Images\CharacterSprites\Haruna.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\ShotsHaruna1.txt");

	LoadSE("\script\SoundEffects\laserm2.wav");
	
	LoadGraphic("\script\Images\OtherEffects\Pulse.png");
	LoadGraphic("\script\Images\OtherEffects\BlackBlur.png");

	LoadGraphic("\script\Images\BackgroundLayers\Haruna2.png");
	LoadGraphic("\script\Images\BackgroundLayers\Haruna3a.png");
	LoadGraphic("\script\Images\CharacterSprites\Haruna.png");

	SetScore(300000);
	SetLife(300);
	SetTimer(50);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	
	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetCommonData("Boss1Vanish",1);

	SetMovePosition02(cx,cy,50);
}
	
@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=5; }
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("Psychoanalysis [Mind-blindness] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


if(time==150){
let angle=rand(0,360);
	loop(3){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Haruna - Mind-Blindness - Familiar.txt",GetX,GetY,0,0,[angle,1]);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Haruna - Mind-Blindness - Familiar.txt",GetX,GetY,0,0,[angle,2]);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Haruna - Mind-Blindness - Familiar.txt",GetX,GetY,0,0,[angle,3]);
	angle+=360/3;
	}
}


if(time>=60){ usespell=-10; }

if(frame>=120 && frame<180 && time%6==0){
	loop(12){
	CreateLaser01(GetX,GetY,2.5,angle,70,10,99,0);
	angle+=360/12;
	}
angle+=1.2;
PlaySE(SElaserm2);
}
if(frame==240){ angle+=360/26; }
if(frame>=240 && frame<300 && time%6==0){
	loop(12){
	CreateLaser01(GetX,GetY,2.5,angle,70,10,98,0);
	angle+=360/12;
	}
angle-=1.2;
PlaySE(SElaserm2);
}
if(frame==360){ angle+=360/26; frame=120; }


if(time==60){
SetColor(255,0,128);
Concentration01(120);
SetColor(255,255,255);
let effectsize=199;
	effect3=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect3,GetX,GetY);
	ObjEffect_SetScale(effect3,scale,scale);
	ObjEffect_SetAngle(effect3,0,0,time*4);
	ObjEffect_SetLayer(effect3,7); ObjEffect_SetTexture(effect3,GReffect2); ObjEffect_SetRenderState(effect3,ALPHA);
	ObjEffect_SetPrimitiveType(effect3,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect3,4);
	ObjEffect_SetVertexXY(effect3,0,-(effectsize/2),-(effectsize/2)); ObjEffect_SetVertexUV(effect3,0,0,0);
	ObjEffect_SetVertexXY(effect3,1,effectsize/2,-(effectsize/2)); ObjEffect_SetVertexUV(effect3,1,effectsize,0);
	ObjEffect_SetVertexXY(effect3,2,-(effectsize/2),effectsize/2); ObjEffect_SetVertexUV(effect3,2,0,effectsize);
	ObjEffect_SetVertexXY(effect3,3,effectsize/2,effectsize/2); ObjEffect_SetVertexUV(effect3,3,effectsize,effectsize);
	ObjEffect_SetVertexColor(effect3,0,255,255,255,255); ObjEffect_SetVertexColor(effect3,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect3,2,255,255,255,255); ObjEffect_SetVertexColor(effect3,3,255,255,255,255);
}

if(GetLife>0){
	if(time>=90){
	if(scale<1.5){ scale+=1.5/90; }
	Obj_SetPosition(effect3,GetX,GetY);
	ObjEffect_SetScale(effect3,scale+0.9-(GetLife/450),scale+0.9-(GetLife/450));
	ObjEffect_SetAngle(effect3,0,0,time*5);
	}
}

if(GetLife<=0){
	if(scale>0.01){ scale-=scale/10; }
	ObjEffect_SetScale(effect3,scale,scale);
	if(scale<=0.01){ Obj_Delete(effect3); }
}



if(time%10==0 && GetLife>0){
let choice1=rand_int(0,3);
let dir1=choice1*90;
let rad1=rand(0,360);
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetX+30*cos(rad1),GetY+30*sin(rad1));
	ObjEffect_SetScale(effect1,2,2);
	Obj_SetAngle(effect1,dir1); Obj_SetSpeed(effect1,4);
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,GReffect1); ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-7.5,-7.5); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,7.5,-7.5); ObjEffect_SetVertexUV(effect1,1,15,0);
	ObjEffect_SetVertexXY(effect1,2,-7.5,7.5); ObjEffect_SetVertexUV(effect1,2,0,15);
	ObjEffect_SetVertexXY(effect1,3,7.5,7.5); ObjEffect_SetVertexUV(effect1,3,15,15);
	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;
	angle1=angle1~[effect1];
	angle1[length(object1)-1]=dir1;
}

if(time>=0){
let i=0;
	while(i<length(object1)){
		if(Obj_BeDeleted(object1[i])){
		object1=erase(object1,i); timer1=erase(timer1,i); i--;
		}
		else{
		timer1[i]=timer1[i]+1;
			if(timer1[i]%5==0){
			let choice1=rand_int(0,2);
			let dir1=0;
			if(choice1==0){ dir1=-90; }
			if(choice1==1){ dir1=90; }
			if(choice1==2){ dir1=0; }
			Obj_SetAngle(object1[i],Obj_GetAngle(object1[i])+dir1);
			ObjEffect_SetAngle(object1[i],0,0,Obj_GetAngle(object1[i]));
			}
		ObjEffect_SetScale(object1[i],1-timer1[i]/60,1-timer1[i]/60);
			if(timer1[i]>=20){ Obj_Delete(object1[i]); }

		effect2=(Obj_Create(OBJ_EFFECT));
		Obj_SetPosition(effect2,Obj_GetX(object1[i]),Obj_GetY(object1[i]));
		ObjEffect_SetScale(effect2,1,1);
		Obj_SetAngle(effect2,0); Obj_SetSpeed(effect2,0);
		ObjEffect_SetLayer(effect2,1); ObjEffect_SetTexture(effect2,GReffect1); ObjEffect_SetRenderState(effect2,ADD);
		ObjEffect_SetPrimitiveType(effect2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect2,4);
		ObjEffect_SetVertexXY(effect2,0,-5,-5); ObjEffect_SetVertexUV(effect2,0,0,0);
		ObjEffect_SetVertexXY(effect2,1,5,-5); ObjEffect_SetVertexUV(effect2,1,15,0);
		ObjEffect_SetVertexXY(effect2,2,-5,5); ObjEffect_SetVertexUV(effect2,2,0,15);
		ObjEffect_SetVertexXY(effect2,3,5,5); ObjEffect_SetVertexUV(effect2,3,15,15);
		ObjEffect_SetVertexColor(effect2,0,255,255,255,255); ObjEffect_SetVertexColor(effect2,1,255,255,255,255);
		ObjEffect_SetVertexColor(effect2,2,255,255,255,255); ObjEffect_SetVertexColor(effect2,3,255,255,255,255);
		object2=object2~[effect2];
		timer2=timer2~[effect2];
		timer2[length(object2)-1]=0;
		}
	i++;
	}
}

let i=0;
while(i<length(object2)){
	if(Obj_BeDeleted(object2[i])){
	object2=erase(object2,i); timer2=erase(timer2,i); i--;
	}
	else{
	timer2[i]=timer2[i]+1;
	ObjEffect_SetScale(object2[i],1-timer2[i]/50,1-timer2[i]/50);
	if(timer2[i]>=50){ Obj_Delete(object2[i]); }
	}
i++;
}


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

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0+time,0,300+time,300);
	SetGraphicScale(1.75,1.75);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(128+127*cos((time+0)),128+127*cos((time+120)),128+127*cos((time+240)));
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,-time/2.5);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0-time,0,600-time,600);
	SetGraphicScale(1,1);
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	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";
}

}