script_enemy_main{

let shot1=0;
let bullet1=[];
let timer1=[];
let accel1=[];
let radius1=[];
let movetime1=[];

let type=rand_int(1,3);
let angle=0;
let radiusa=0;
let radiusb=0;
let enemyangle=rand_int(0,360);
let mover=rand_int(0,360);

let oldx=0;

let character="Nanami";
let cutin=character;
let spellcards=2;
let spellcardnumber=44;
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 SEping=("\script\SoundEffects\ping1.wav");
let SEshotb6=("\script\SoundEffects\shotb6.wav");
let SEshotb7=("\script\SoundEffects\shotb7.wav");
let SEshotm2=("\script\SoundEffects\shotm2.wav");
let SEshots3=("\script\SoundEffects\shots3.wav");
let SEshots4=("\script\SoundEffects\shots4.wav");
let SEshots5=("\script\SoundEffects\shots5.wav");

let BG1=("\script\Images\BackgroundLayers\Nanami1.png");
let BG2=("\script\Images\BackgroundLayers\Nanami2.png");
let GRboss=("\script\Images\CharacterSprites\Nanami.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\ShotsNanami1.txt");

	LoadGraphic("\script\Images\CharacterSprites\Nanami.png");
	LoadGraphic("\script\Images\BackgroundLayers\Nanami1.png");
	LoadGraphic("\script\Images\BackgroundLayers\Nanami2.png");
	
	LoadSE("script\SoundEffects\ping1.wav");
	LoadSE("script\SoundEffects\shotb6.wav");
	LoadSE("script\SoundEffects\shotb7.wav");
	LoadSE("script\SoundEffects\shotm2.wav");
	LoadSE("script\SoundEffects\shots3.wav");
	LoadSE("script\SoundEffects\shots4.wav");
	LoadSE("script\SoundEffects\shots5.wav");
	
	SetScore(500000);
	SetLife(150);
	SetTimer(60);
	SetInvincibility(120);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,cy,50);
}
	
@MainLoop{

oldx=GetX;
SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(128,128,128,128);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; if(GetTimer<=40){ damagerate=20; } }
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("Main Dish [Pizza Margherita]",spellcardnumber);

HealthBar();
Portrait(cutin,1);


if(time>=120){ SetX(cx+(radiusa+radiusb)*cos(enemyangle)); SetY(cy+(radiusa+radiusb)*sin(enemyangle)); }
if(time>=120 && radiusa<130){ radiusa+=1; }
radiusb=30*cos(time*1.2);
if(time>=240){ enemyangle+=0.5; }


if(time>=300 && time%7==0){
CreateShot01(cx,cy,0.8,-(time/4),13,0);
CreateShot01(cx,cy,0.8,-(time/4)+180,13,0);
}
if(time>=1200 && time%7==0){
CreateShot01(cx,cy,0.8,-(time/4)+90,14,0);
CreateShot01(cx,cy,0.8,-(time/4)+270,14,0);
}


if(time>=210 && time%10==0){
let shot1=0;
SetShotColor(255,100,100);
	CreateShotA(shot1,GetX,GetY,0);
	SetShotDataA(shot1,0,rand(0.3,0.7),enemyangle,0,0,0,25);
	FireShot(shot1);
	CreateShotA(shot1,GetX,GetY,0);
	SetShotDataA(shot1,0,rand(0.3,0.7),enemyangle+180,0,0,0,25);
	FireShot(shot1);
SetShotColor(255,255,255);
PlaySE(SEshots4);
}

if(time>=210 && (time+10)%120==0){
let shot1=0;
SetShotColor(60,60,60);
	CreateShotA(shot1,GetX,GetY,0);
	SetShotDataA(shot1,0,rand(0.3,0.7),enemyangle+rand(90,-90),0,0,0,60);
	FireShot(shot1);
SetShotColor(255,255,255);
PlaySE(SEshots5);
}


if(time>=90 && angle<180){
let angle2=0;
	loop(2){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,cx,cy);
	Obj_SetAngle(shot1,angle+angle2);
	Obj_SetSpeed(shot1,2);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,3);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	accel1=accel1~[shot1];
	accel1[length(bullet1)-1]=0;
	radius1=radius1~[shot1];
	radius1[length(bullet1)-1]=0;
	movetime1=movetime1~[shot1];
	movetime1[length(bullet1)-1]=150;
	angle+=1.5;
	angle2=178.5;
	}
	if(time%5==0){ PlaySE(SEshotb7); }
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); accel1=erase(accel1,i);
	radius1=erase(radius1,i); movetime1=erase(movetime1,i);
	i--;
	}
	else{
		if(timer1[i]==0){
		Obj_SetAngle(bullet1[i],atan2(cx+200*cos(Obj_GetAngle(bullet1[i]))-Obj_GetY(bullet1[i]),cy+200*sin(Obj_GetAngle(bullet1[i]))-Obj_GetX(bullet1[i])));
		radius1[i]=(((cx+200*cos(Obj_GetAngle(bullet1[i]))-Obj_GetX(bullet1[i]))^2+(cy+200*sin(Obj_GetAngle(bullet1[i]))-Obj_GetY(bullet1[i]))^2)^0.5)/movetime1[i]*(pi/2);
		Obj_SetSpeed(bullet1[i],0);			
		}

		if(timer1[i]>=0 && timer1[i]<movetime1[i]){
		accel1[i]=accel1[i]+180/movetime1[i];
		Obj_SetSpeed(bullet1[i],radius1[i]*sin(accel1[i]));
		}

		if(timer1[i]==movetime1[i]){
		}
	timer1[i]=timer1[i]+1;
	}
i++;
}


if(time>=300 && time%100==0){
let shot1=1;
	if(type==1){
	let angle2=rand(0,360);
	let speed=rand(1.5,2);
	SetShotColor(200,150,150);
		loop(8){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,speed,angle2,0,-0.05,0,37);
		SetShotDataA(shot1,150,NULL,NULL,0,0.02,1,37);
		FireShot(shot1);
		angle2+=360/8;
		}
	PlaySE(SEshotb6);
	SetShotColor(255,255,255);
	}
	if(type==2){
	let angle2=rand(0,360);
	SetShotColor(100,200,0);
		loop(20){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,rand(1.5,2),angle2,0,-0.05,0,64);
		SetShotDataA(shot1,150,NULL,rand(0,360),0,0.02,1,64);
		FireShot(shot1);
		angle2+=360/20;
		}
	PlaySE(SEshotm2);
	SetShotColor(255,255,255);
	}
	if(type==3){
	let angle2=rand(0,360);
		loop(50){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,rand(0.3,0.7),angle2,0,-0.002,0.1,75);
		SetShotKillTime(shot1,rand_int(400,500));
		FireShot(shot1);
		angle2+=360/50;
		}
	PlaySE(SEshots3);
	}
usespell=-20;
type+=rand_int(1,2);
if(type>3){ type-=3; }
}

mover++;

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

	SetGraphicRect(0,0,588,588);
	SetGraphicScale(1,1);
	SetTexture(BG1);
	SetAlpha(255);
	SetColor(bgfade,bgfade,bgfade);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0,0,300,300);
	SetGraphicScale(1.4,1.4);
	SetTexture(BG2);
	SetGraphicAngle(0,0,-(time/3));
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	SetGraphicRect(0,outfit,128,outfit+128);

	if((((oldx-GetX)^2+(cy-cy)^2)^0.5)>0.2){
	if(GetX<oldx){ SetGraphicRect(128,outfit,256,outfit+128); }
	if(GetX>oldx){ SetGraphicRect(256,outfit,384,outfit+128); }
	}

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }

	DrawGraphic(GetX,GetY);
}

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

}