script_enemy_main{

let speed=1;

let effect1=0;
let effect2=0;
let effect3=0;
let fade1=0;
let fade2=0;
let lightangle=90;

let character="Midori";
let cutin=character;
let dispelled=0;
let spellcards=2;
let spellcardnumber=26;
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 EFflashlight1=("\script\Images\OtherEffects\Flashlight1.png");
let EFflashlight2=("\script\Images\OtherEffects\Flashlight2.png");
let EFflashlight3=("\script\Images\OtherEffects\Wall.png");

let SEshotm1=("\script\SoundEffects\shotm1.wav");
let SEshotb2=("\script\SoundEffects\shotb2.wav");

let BG1=("\script\Images\BackgroundLayers\Midori1.png");
let GRboss=("\script\Images\CharacterSprites\Midori.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\ShotsMidori1.txt");

	LoadGraphic("\script\Images\OtherEffects\Flashlight1.png");
	LoadGraphic("\script\Images\OtherEffects\Flashlight2.png");
	LoadGraphic("\script\Images\OtherEffects\Wall.png");

	LoadSE("\script\SoundEffects\shotm1.wav");
	LoadSE("\script\SoundEffects\shotb2.wav");

	LoadGraphic("\script\Images\CharacterSprites\Midori.png");
	LoadGraphic("\script\Images\BackgroundLayers\Midori1.png");

	SetScore(250000);
	SetLife(150);
	SetTimer(30);
	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,miny+100,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=3; }
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("Nyctohylophobia [Fear Of Forests At Night] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


if(time==0){
let xsize=600;
let ysize=600;
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetX,GetY);
	ObjEffect_SetScale(effect1,6,3); ObjEffect_SetAngle(effect1,0,0,GetAngleToPlayer-90);
	ObjEffect_SetLayer(effect1,6); ObjEffect_SetTexture(effect1,EFflashlight1); ObjEffect_SetRenderState(effect1,ADD);
	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,255,fade1,fade1,fade1); ObjEffect_SetVertexColor(effect1,1,255,fade1,fade1,fade1);
	ObjEffect_SetVertexColor(effect1,2,255,fade1,fade1,fade1); ObjEffect_SetVertexColor(effect1,3,255,fade1,fade1,fade1);
	effect2=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect2,GetX,GetY);
	ObjEffect_SetScale(effect2,6,3); ObjEffect_SetAngle(effect2,0,0,GetAngleToPlayer-90);
	ObjEffect_SetLayer(effect2,6); ObjEffect_SetTexture(effect2,EFflashlight2); ObjEffect_SetRenderState(effect2,ALPHA);
	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,fade1,255,255,255); ObjEffect_SetVertexColor(effect2,1,fade1,255,255,255);
	ObjEffect_SetVertexColor(effect2,2,fade1,255,255,255); ObjEffect_SetVertexColor(effect2,3,fade1,255,255,255);
	effect3=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect3,cx,cy);
	ObjEffect_SetScale(effect3,1,1);
	ObjEffect_SetLayer(effect3,6); ObjEffect_SetTexture(effect3,EFflashlight3); ObjEffect_SetRenderState(effect3,ALPHA);
	ObjEffect_SetPrimitiveType(effect3,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect3,4);
	ObjEffect_SetVertexXY(effect3,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect3,0,0,0);
	ObjEffect_SetVertexXY(effect3,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect3,1,xsize,0);
	ObjEffect_SetVertexXY(effect3,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect3,2,0,ysize);
	ObjEffect_SetVertexXY(effect3,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect3,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect3,0,fade2,0,0,0); ObjEffect_SetVertexColor(effect3,1,fade2,0,0,0);
	ObjEffect_SetVertexColor(effect3,2,fade2,0,0,0); ObjEffect_SetVertexColor(effect3,3,fade2,0,0,0);
}


if(time%50==0 && time>=60){
let angle=rand(0,360);
let shot1=0;
let dir=0;
if(time%100==0){ dir=speed; }
if(time%100!=0){ dir=-speed; }
	loop(100){
	CreateShotA(shot1,GetX,GetY,0);
	SetShotDataA(shot1,0,4,angle,dir,-0.05,1.5,65);
	SetShotDataA(shot1,60,NULL,NULL,0,-0.05,1.5,65);
	FireShot(shot1);
	angle+=360/100;
	}
if(speed<2){ speed+=0.05; }
usespell=20;
PlaySE(SEshotm1);
}

if((time+25)%110==0 && time>=60){
let angle=GetAngleToPlayer-45;
	loop(7){
	CreateShot01(GetX,GetY,2.5,angle,76,0);
	angle+=15;
	}
PlaySE(SEshotb2);
}


if(frame>=250 && frame<260 && time%3==0){ fade2=rand_int(80,140); }
if(frame==260){ fade2=20; }
if(frame>=390 && frame<415 && time%3==0){ fade2=rand_int(130,200); }
if(frame==415){ fade2=80; }
if(frame>=435 && frame<480 && time%5==0){ fade2=rand_int(170,255); }
if(frame==480){ fade2=150; }
if(frame>=560 && frame<590 && time%3==0){ fade2=rand_int(200,230); }
if(frame==590){ fade2=225; }
if(frame>=635 && frame<670 && time%3==0){ fade2=rand_int(120,180); }
if(frame==670){ frame=160; fade2=0; }

lightangle=35*cos(time*0.65);
	Obj_SetPosition(effect1,GetX,GetY);
	Obj_SetPosition(effect2,GetX,GetY);
	ObjEffect_SetAngle(effect1,0,0,lightangle);
	ObjEffect_SetAngle(effect2,0,0,lightangle);
	ObjEffect_SetVertexColor(effect1,0,255,fade1,fade1,fade1); ObjEffect_SetVertexColor(effect1,1,255,fade1,fade1,fade1);
	ObjEffect_SetVertexColor(effect1,2,255,fade1,fade1,fade1); ObjEffect_SetVertexColor(effect1,3,255,fade1,fade1,fade1);
	ObjEffect_SetVertexColor(effect2,0,fade1,255,255,255); ObjEffect_SetVertexColor(effect2,1,fade1,255,255,255);
	ObjEffect_SetVertexColor(effect2,2,fade1,255,255,255); ObjEffect_SetVertexColor(effect2,3,fade1,255,255,255);
	ObjEffect_SetVertexColor(effect3,0,fade2,0,0,0); ObjEffect_SetVertexColor(effect3,1,fade2,0,0,0);
	ObjEffect_SetVertexColor(effect3,2,fade2,0,0,0); ObjEffect_SetVertexColor(effect3,3,fade2,0,0,0);
if(fade1<255){ fade1++; }


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<125){ bgfade+=5; }

	SetGraphicRect(0,0,600,600);
	SetGraphicScale(2,2);
	SetTexture(BG1);
	SetRenderState(ALPHA);
	
	SetAlpha(bgfade*2);
	SetColor(127+127*cos(time),127+127*cos(time+120),127+127*cos(time+240));
	SetGraphicAngle(0,0,-time);
	DrawGraphic(cx-150,cy);
	
	SetColor(127-127*cos(time),127-127*cos(time+120),127-127*cos(time+240));
	SetAlpha(bgfade);
	SetGraphicAngle(0,0,time);
	DrawGraphic(cx+150,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";
}

}