task LoadShot{
	let current = GetCurrentScriptDirectory();
	let path = current ~ "allstarshot.txt";
	LoadEnemyShotData(path);
}

task animateBossEternity{
	let dir;
	let speed;
	let hover = 0;
	let w = 5;

	let l = 80;
	let h = 96;
	let animFrame = 0;
	let animFrame2 = 0;
	let animFrame3 = 0;
	BossAura(bossObj,255,60,60, 255,0,0);

	while(!Obj_IsDeleted(bossObj)){
	ObjPrim_SetTexture(bossObj,GetCurrentScriptDirectory ~ "img/stgenm/stage01/enm1.png");
	ObjSprite2D_SetDestRect(bossObj,-l/2,-h/2+4*cos(hover),l/2,h/2+4*cos(hover));
	hover+=2;

		dir = ObjMove_GetAngle(bossObj);
		speed = ObjMove_GetSpeed(bossObj);

		if(speed==0){
			ObjRender_SetAngleY(bossObj,0);
			if(animFrame < w){ObjSprite2D_SetSourceRect(bossObj,0,0,l,h);}
			if(animFrame >= w && animFrame < w*2){ObjSprite2D_SetSourceRect(bossObj,l,0,l*2,h);}
			if(animFrame >= w*2 && animFrame < w*3){ObjSprite2D_SetSourceRect(bossObj,l*2,0,l*3,h);}
			if(animFrame >= w*3  && animFrame < w*4){ObjSprite2D_SetSourceRect(bossObj,l*3,0,l*4,h);}
			if(animFrame >= w*4  && animFrame < w*5){ObjSprite2D_SetSourceRect(bossObj,l*4,0,l*5,h);}
			if(animFrame >= w*5){ObjSprite2D_SetSourceRect(bossObj,l*5,0,l*6,h);}
			animFrame2 = 0;}
		else if(cos(dir) > 0){
			ObjRender_SetAngleY(bossObj,0);
			if(animFrame2 < w){ObjSprite2D_SetSourceRect(bossObj,0,h,l,h*2);}
			if(animFrame2 >= w && animFrame2 < w*2){ObjSprite2D_SetSourceRect(bossObj,l,h,l*2,h*2);}
			if(animFrame2 >= w*2 && animFrame2 < w*3){ObjSprite2D_SetSourceRect(bossObj,l*2,h,l*3,h*2);}
			if(animFrame2 >= w*3 && animFrame2 < w*4){ObjSprite2D_SetSourceRect(bossObj,l*3,h,l*4,h*2);}
			if(animFrame2 >= w*4 && animFrame2 < w*5){ObjSprite2D_SetSourceRect(bossObj,l*4,h,l*5,h*2);}
			if(animFrame2 >= w*5){ObjSprite2D_SetSourceRect(bossObj,l*5,h,l*6,h*2);}
			}
		else if(cos(dir) < 0){
			ObjRender_SetAngleY(bossObj,180);
			if(animFrame2 < w){ObjSprite2D_SetSourceRect(bossObj,0,h,l,h*2);}
			if(animFrame2 >= w && animFrame2 < w*2){ObjSprite2D_SetSourceRect(bossObj,l,h,l*2,h*2);}
			if(animFrame2 >= w*2 && animFrame2 < w*3){ObjSprite2D_SetSourceRect(bossObj,l*2,h,l*3,h*2);}
			if(animFrame2 >= w*3 && animFrame2 < w*4){ObjSprite2D_SetSourceRect(bossObj,l*3,h,l*4,h*2);}
			if(animFrame2 >= w*4 && animFrame2 < w*5){ObjSprite2D_SetSourceRect(bossObj,l*4,h,l*5,h*2);}
			if(animFrame2 >= w*5){ObjSprite2D_SetSourceRect(bossObj,l*5,h,l*6,h*2);}
			}

		if(attack==1){
			ObjRender_SetAngleY(bossObj,0);
			if(animFrame3 < w){ObjSprite2D_SetSourceRect(bossObj,0,h*2,l,h*3);}
			if(animFrame3 >= w && animFrame3 < w*2){ObjSprite2D_SetSourceRect(bossObj,l,h*2,l*2,h*3);}
			if(animFrame3 >= w*2 && animFrame3 < w*3){ObjSprite2D_SetSourceRect(bossObj,l*2,h*2,l*3,h*3);}
			if(animFrame3 >= w*3 && animFrame3 < w*4){ObjSprite2D_SetSourceRect(bossObj,l*3,h*2,l*4,h*3);}
			if(animFrame3 >= w*4 && animFrame3 < w*5){ObjSprite2D_SetSourceRect(bossObj,l*4,h*2,l*5,h*3);}
			if(animFrame3 >= w*5){ObjSprite2D_SetSourceRect(bossObj,l*5,h*2,l*6,h*3);}
			animFrame3++;}

		if(attack==0){animFrame3 = 0;}

		animFrame++;
		animFrame2++;
		if(animFrame > w*6){animFrame = 0;}
		if(animFrame3 > w*6){animFrame3 = 0;}
		yield;}
	return;
}

task animateBossSakata{
	let dir;
	let speed;
	let hover = 0;
	let w = 5;

	let l = 64;
	let h = 96;
	let animFrame = 0;
	let animFrame2 = 0;
	let animFrame3 = 0;
	BossAura(bossObj,255,60,180, 0,0,255);

	while(!Obj_IsDeleted(bossObj)){
	ObjPrim_SetTexture(bossObj,GetCurrentScriptDirectory ~ "img/stgenm/stage02/enm2.png");
	ObjSprite2D_SetDestRect(bossObj,-l/2,-h/2+4*cos(hover),l/2,h/2+4*cos(hover));
	hover+=2;

		dir = ObjMove_GetAngle(bossObj);
		speed = ObjMove_GetSpeed(bossObj);

		if(speed==0){
			ObjRender_SetAngleY(bossObj,0);
			if(animFrame < w){ObjSprite2D_SetSourceRect(bossObj,0,0,l,h);}
			if(animFrame >= w && animFrame < w*2){ObjSprite2D_SetSourceRect(bossObj,l,0,l*2,h);}
			if(animFrame >= w*2 && animFrame < w*3){ObjSprite2D_SetSourceRect(bossObj,l*2,0,l*3,h);}
			if(animFrame >= w*3){ObjSprite2D_SetSourceRect(bossObj,l*3,0,l*4,h);}
			animFrame2 = 0;}
		else if(cos(dir) > 0){
			ObjRender_SetAngleY(bossObj,0);
			if(animFrame2 < w){ObjSprite2D_SetSourceRect(bossObj,0,h,l,h*2);}
			if(animFrame2 >= w && animFrame2 < w*2){ObjSprite2D_SetSourceRect(bossObj,l,h,l*2,h*2);}
			if(animFrame2 >= w*2 && animFrame2 < w*3){ObjSprite2D_SetSourceRect(bossObj,l*2,h,l*3,h*2);}
			if(animFrame2 >= w*3 && animFrame2 < w*4){ObjSprite2D_SetSourceRect(bossObj,l*3,h,l*4,h*2);}
			if(animFrame2 >= w*4 && animFrame2 < w*5){ObjSprite2D_SetSourceRect(bossObj,l*4,h,l*5,h*2);}
			if(animFrame2 >= w*5 && animFrame2 < w*6){ObjSprite2D_SetSourceRect(bossObj,l*5,h,l*6,h*2);}
			if(animFrame2 >= w*6){ObjSprite2D_SetSourceRect(bossObj,l*6,h,l*7,h*2);}
			}
		else if(cos(dir) < 0){
			ObjRender_SetAngleY(bossObj,180);
			if(animFrame2 < w){ObjSprite2D_SetSourceRect(bossObj,0,h,l,h*2);}
			if(animFrame2 >= w && animFrame2 < w*2){ObjSprite2D_SetSourceRect(bossObj,l,h,l*2,h*2);}
			if(animFrame2 >= w*2 && animFrame2 < w*3){ObjSprite2D_SetSourceRect(bossObj,l*2,h,l*3,h*2);}
			if(animFrame2 >= w*3 && animFrame2 < w*4){ObjSprite2D_SetSourceRect(bossObj,l*3,h,l*4,h*2);}
			if(animFrame2 >= w*4 && animFrame2 < w*5){ObjSprite2D_SetSourceRect(bossObj,l*4,h,l*5,h*2);}
			if(animFrame2 >= w*5 && animFrame2 < w*6){ObjSprite2D_SetSourceRect(bossObj,l*5,h,l*6,h*2);}
			if(animFrame2 >= w*6){ObjSprite2D_SetSourceRect(bossObj,l*6,h,l*7,h*2);}
			}

		if(attack==1){
			ObjRender_SetAngleY(bossObj,0);
			if(animFrame3 < w){ObjSprite2D_SetSourceRect(bossObj,0,h*2,l,h*3);}
			if(animFrame3 >= w && animFrame3 < w*2){ObjSprite2D_SetSourceRect(bossObj,l,h*2,l*2,h*3);}
			if(animFrame3 >= w*2 && animFrame3 < w*3){ObjSprite2D_SetSourceRect(bossObj,l*2,h*2,l*3,h*3);}
			if(animFrame3 >= w*3 && animFrame3 < w*4){ObjSprite2D_SetSourceRect(bossObj,l*3,h*2,l*4,h*3);}
			if(animFrame3 >= w*4 && animFrame3 < w*5){ObjSprite2D_SetSourceRect(bossObj,l*4,h*2,l*5,h*3);}
			if(animFrame3 >= w*5 && animFrame3 < w*6){ObjSprite2D_SetSourceRect(bossObj,l*5,h*2,l*6,h*3);}
			if(animFrame3 >= w*6){ObjSprite2D_SetSourceRect(bossObj,l*6,h*2,l*7,h*3);}
			animFrame3++;}

		if(attack==0){animFrame3 = 0;}

		animFrame++;
		animFrame2++;
		if(animFrame > w*4){animFrame = 0;}
		if(animFrame3 > w*7){animFrame3 = w*3;}
		yield;}
	return;
}

task animateBossAunn(obj){
	let dir;
	let speed;
	let hover = 0;
	let w = 8;

	let l = 64;
	let h = 96;
	let animFrame = 0;
	let animFrame2 = 0;
	let animFrame3 = 0;
	BossAura(obj,255,60,60, 255,0,0);

	while(!Obj_IsDeleted(obj)){
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "img/stgenm/stage03/enm3.png");
	ObjSprite2D_SetDestRect(obj,-l/2,-h/2+4*cos(hover),l/2,h/2+4*cos(hover));
	hover+=2;

		dir = ObjMove_GetAngle(obj);
		speed = ObjMove_GetSpeed(obj);

		if(speed==0){
			ObjRender_SetAngleY(obj,0);
			if(animFrame < w){ObjSprite2D_SetSourceRect(obj,0,0,l,h);}
			if(animFrame >= w && animFrame < w*2){ObjSprite2D_SetSourceRect(obj,l,0,l*2,h);}
			if(animFrame >= w*2 && animFrame < w*3){ObjSprite2D_SetSourceRect(obj,l*2,0,l*3,h);}
			if(animFrame >= w*3  && animFrame < w*4){ObjSprite2D_SetSourceRect(obj,l*3,0,l*4,h);}
			if(animFrame >= w*4  && animFrame < w*5){ObjSprite2D_SetSourceRect(obj,l*4,0,l*5,h);}
			if(animFrame >= w*5 && animFrame < w*6){ObjSprite2D_SetSourceRect(obj,l*5,0,l*6,h);}
			if(animFrame >= w*6 && animFrame < w*7){ObjSprite2D_SetSourceRect(obj,l*6,0,l*7,h);}
			if(animFrame >= w*7){ObjSprite2D_SetSourceRect(obj,l*7,0,l*8,h);}
			animFrame2 = 0;}
		else if(cos(dir) > 0){
			ObjRender_SetAngleY(obj,0);
			if(animFrame2 < w){ObjSprite2D_SetSourceRect(obj,0,h,l,h*2);}
			if(animFrame2 >= w && animFrame2 < w*2){ObjSprite2D_SetSourceRect(obj,l,h,l*2,h*2);}
			if(animFrame2 >= w*2 && animFrame2 < w*3){ObjSprite2D_SetSourceRect(obj,l*2,h,l*3,h*2);}
			if(animFrame2 >= w*3 && animFrame2 < w*4){ObjSprite2D_SetSourceRect(obj,l*3,h,l*4,h*2);}
			if(animFrame2 >= w*4 && animFrame2 < w*5){ObjSprite2D_SetSourceRect(obj,l*4,h,l*5,h*2);}
			if(animFrame2 >= w*5){ObjSprite2D_SetSourceRect(obj,l*5,h,l*6,h*2);}
			}
		else if(cos(dir) < 0){
			ObjRender_SetAngleY(obj,180);
			if(animFrame2 < w){ObjSprite2D_SetSourceRect(obj,0,h,l,h*2);}
			if(animFrame2 >= w && animFrame2 < w*2){ObjSprite2D_SetSourceRect(obj,l,h,l*2,h*2);}
			if(animFrame2 >= w*2 && animFrame2 < w*3){ObjSprite2D_SetSourceRect(obj,l*2,h,l*3,h*2);}
			if(animFrame2 >= w*3 && animFrame2 < w*4){ObjSprite2D_SetSourceRect(obj,l*3,h,l*4,h*2);}
			if(animFrame2 >= w*4 && animFrame2 < w*5){ObjSprite2D_SetSourceRect(obj,l*4,h,l*5,h*2);}
			if(animFrame2 >= w*5){ObjSprite2D_SetSourceRect(obj,l*5,h,l*6,h*2);}
			}

		if(attack==1){
			ObjRender_SetAngleY(obj,0);
			if(animFrame3 < w){ObjSprite2D_SetSourceRect(obj,0,h*2,l,h*3);}
			if(animFrame3 >= w && animFrame3 < w*2){ObjSprite2D_SetSourceRect(obj,l,h*2,l*2,h*3);}
			if(animFrame3 >= w*2 && animFrame3 < w*3){ObjSprite2D_SetSourceRect(obj,l*2,h*2,l*3,h*3);}
			if(animFrame3 >= w*3 && animFrame3 < w*4){ObjSprite2D_SetSourceRect(obj,l*3,h*2,l*4,h*3);}
			if(animFrame3 >= w*4 && animFrame3 < w*5){ObjSprite2D_SetSourceRect(obj,l*4,h*2,l*5,h*3);}
			if(animFrame3 >= w*5  && animFrame3 < w*6){ObjSprite2D_SetSourceRect(obj,l*5,h*2,l*6,h*3);}
			if(animFrame3 >= w*6  && animFrame3 < w*7){ObjSprite2D_SetSourceRect(obj,l*6,h*2,l*7,h*3);}
			if(animFrame3 >= w*7){ObjSprite2D_SetSourceRect(obj,l*7,h*2,l*8,h*3);}
			animFrame3++;}

		if(attack==0){animFrame3 = 0;}

		animFrame++;
		animFrame2++;
		if(animFrame > w*8){animFrame = 0;}
		if(animFrame3 > w*8){animFrame3 = 0;}
		yield;}
	return;
}

task animateBossLily{
	let hover = 0;
	let w = 5;

	let l = 64;
	let k = 96*3;
	let h = 354-k;
	let animFrame = 0;
	BossAura(bossObj,60,60,255, 0,0,255);

	while(!Obj_IsDeleted(bossObj)){
		ObjPrim_SetTexture(bossObj,GetCurrentScriptDirectory ~ "img/stgenm/stage03/enm3.png");
		ObjSprite2D_SetDestRect(bossObj,-l/2,-h/2+4*cos(hover),l/2,h/2+4*cos(hover));

		if(animFrame < w){ObjSprite2D_SetSourceRect(bossObj,0,k,l,k+h);}
		if(animFrame >= w && animFrame < w*2){ObjSprite2D_SetSourceRect(bossObj,l,k,l*2,k+h);}
		if(animFrame >= w*2 && animFrame < w*3){ObjSprite2D_SetSourceRect(bossObj,l*2,k,l*3,k+h);}
		if(animFrame >= w*3){ObjSprite2D_SetSourceRect(bossObj,l*3,k,l*4,k+h);}
		if(animFrame >= w*4){animFrame = 0;}
		animFrame++;
		hover+=2;
		yield;}
	return;
}

function CreateFamilar(x,y){
	let fam = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(fam);
	ObjEnemy_SetLife(fam,100);
	Obj_SetRenderPriorityI(fam,40);
	ObjRender_SetPosition(fam,x,y,0);
	animateBossAunn(fam);
	return fam;}

#include"./[library] effects.txt"
#include"./[library] se.txt"
task TEndScript{
	while(!IsCloseScript(GetOwnScriptID)){
		let x = ObjMove_GetX(bossObj);
		let y = ObjMove_GetY(bossObj);
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){ 
			SaveCommonDataAreaA2("HiScore",GetCurrentScriptDirectory ~ "./data/hiscore.dat");
			MakeExplosionA2(x,y,"SAKURA",255,255,255); SE(se_enep2);
			DeleteShotAll(TYPE_CHILD,TYPE_FADE);
			Obj_Delete(bossObj);
			loop(180){yield;}
			SetCommonData("MENU",1);
			SetCommonData("CHECK","YES");
			CloseScript(GetOwnScriptID());
		return;}
		
		if(GetPlayerLife < 1){
			SaveCommonDataAreaA2("HiScore",GetCurrentScriptDirectory ~ "./data/hiscore.dat");
			ObjEnemy_SetLife(bossObj,0);
			SetCommonData("EFFECT",1);
			effectBrake;
			Obj_Delete(bossObj);
			DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
			loop(100){yield;}
			SetCommonData("MENU",1);
			SetCommonData("EFFECT",0);
			SetCommonData("CHECK","NO");
			CloseScript(GetOwnScriptID());
		return;}
	yield;}
}

task effectBrake{
	SaveSnapShotA2(GetCurrentScriptDirectory ~ "./img/menueffect.png",32,16,416,464);

	let objbg = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objbg,GetCurrentScriptDirectory ~ "./img/menueffect.png");
	Obj_SetRenderPriorityI(objbg,70);
	ObjSprite2D_SetSourceRect(objbg,0,0,384,448);
	ObjSprite2D_SetDestRect(objbg,0,0,384,448);
	ObjRender_SetAlpha(objbg,255);

	ascent(y in 0..18){
		ascent(i in 0..12){
			Primitive(i*32, y*32, 32, 32, 16+i*32, 16+y*32);
		}
	}
	Obj_Delete(objbg);
}

task Primitive(startx,starty,width,length,xpos,ypos){
	let objOutline = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(objOutline, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetTexture(objOutline, GetCurrentScriptDirectory ~ "./img/menueffect.png");

		ObjPrim_SetVertexCount(objOutline, 4);
		Obj_SetRenderPriorityI(objOutline, 80);

		ObjPrim_SetVertexUVT(objOutline, 0, startx, starty);
		ObjPrim_SetVertexUVT(objOutline, 1, startx+width, starty);
		ObjPrim_SetVertexUVT(objOutline, 2, startx+width, starty+length);
		ObjPrim_SetVertexUVT(objOutline, 3, startx, starty+length);

		ObjRender_SetPosition(objOutline, xpos, ypos, 0);

		ObjPrim_SetVertexPosition(objOutline, 0, -width/2, -length/2, 0);
		ObjPrim_SetVertexPosition(objOutline, 1, width/2, -length/2, 0);
		ObjPrim_SetVertexPosition(objOutline, 2, width/2, length/2, 0);
		ObjPrim_SetVertexPosition(objOutline, 3, -width/2, length/2, 0);
		
		loop(1){yield;}
		let rmove = 0;
		let angle = GetAngleToPlayer(objOutline) +180;
		loop(45){
			ObjRender_SetPosition(objOutline,xpos+rmove*cos(angle),ypos+rmove*sin(angle),0);
			ObjRender_SetAngleZ(objOutline, ObjRender_GetAngleZ(objOutline) + 4);
			rmove+=2;
			yield;}
		loop(45){
			ObjRender_SetPosition(objOutline,xpos+rmove*cos(angle),ypos+rmove*sin(angle),0);
			ObjRender_SetAngleX(objOutline, ObjRender_GetAngleX(objOutline) - 2);
			ObjRender_SetAngleY(objOutline, ObjRender_GetAngleY(objOutline) + 2);
			ObjRender_SetAngleZ(objOutline, ObjRender_GetAngleZ(objOutline) + 4);
			rmove+=2;
			yield;}
		Obj_Delete(objOutline);
	}