
//=======================================================================
//　地霊殿以降の敵のオーラを表示する関数集です。
//　このファイルをinclude_functionで取り込むか、
//　必要な部分をコピペして使用してください。
//=======================================================================

//=======================================================================
// ■ 画像へのパス 構成が違う場合は要変更
//-----------------------------------------------------------------------
let imgaura1 = GetCurrentScriptDirectory~"img/Aura01.png";
let imgaura2 = GetCurrentScriptDirectory~"img/Aura02.png";
//=======================================================================

//-----------------------------------------------------------------------
// ■ 敵オーラ [th11〜th14] [一括設定]
//-----------------------------------------------------------------------
function Aura1(enemy,time,R,G,B) {

	Aura1_1_Auto(enemy,time,R,G,B);
	Aura1_2_Auto(enemy,3   ,R,G,B);

}

//-----------------------------------------------------------------------
// ■ 敵オーラ [th11〜th14] [フェードアウト] [表示用関数]
//-----------------------------------------------------------------------
task Aura1_1_Auto(enemy,time,R,G,B) {

	while(!Obj_IsDeleted(enemy)) {
		Aura1_1(enemy,30,R,G,B);
		loop(time) { yield; }
	}
}

//-----------------------------------------------------------------------
// ■ 敵オーラ [th11〜th14] [収束] [表示用関数]
//-----------------------------------------------------------------------
task Aura1_2_Auto(enemy,time,R,G,B) {

	while(!Obj_IsDeleted(enemy)) {
		Aura1_2(enemy,30,R,G,B);
		loop(time) { yield; }
	}
}

//-----------------------------------------------------------------------
// ■ 敵オーラ [th11〜th14] [フェードアウト]
//-----------------------------------------------------------------------
task Aura1_1(enemy,time,R,G,B) {

	let aura	= ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let mY		= 0;
	let pX		= rand(-4,4);
	let angle	= pX*2;
	let alpha1	= 0;
	let alpha2	= 0;
	let scalex1	= 0;
	let scalex2	= 0;
	let scalex3	= rand(1.0,1.4);
	let scaley1	= 0;
	let scaley2	= 0;
	let scaley3	= rand(1.4,1.6);

        let enemy_x = ObjMove_GetX(enemy);
        let enemy_y = ObjMove_GetY(enemy);

	LoadTexture(imgaura1);

	ObjRender_SetPosition(aura,enemy_x+pX,enemy_y-mY,0);
	ObjPrim_SetTexture(aura,imgaura1);
	ObjRender_SetBlendType(aura,BLEND_ADD_RGB);
	ObjPrim_SetPrimitiveType(aura,PRIMITIVE_TRIANGLESTRIP);
	ObjRender_SetScaleXYZ(aura,scalex1,scaley1,1);
	ObjRender_SetAngleXYZ(aura,0,0,angle);
	Obj_SetRenderPriorityI(aura,25);
	ObjPrim_SetVertexCount(aura,4);
	ObjPrim_SetVertexPosition(aura,0,-24,-24,0);
	ObjPrim_SetVertexPosition(aura,1,-24, 24,0);
	ObjPrim_SetVertexPosition(aura,2, 24,-24,0);
	ObjPrim_SetVertexPosition(aura,3, 24, 24,0);
	ObjPrim_SetVertexUVT(aura,0,  0,  0);
	ObjPrim_SetVertexUVT(aura,1,  0, 48);
	ObjPrim_SetVertexUVT(aura,2, 48,  0);
	ObjPrim_SetVertexUVT(aura,3, 48, 48);

	loop(time) {

		mY      += 56/time;
		alpha2  += 180/time;
		alpha1   = 255*sin(alpha2);
		scalex2 += 135/time;
		scaley2 += 90 /time;
		scalex1  = scalex3*sin(scalex2);
		scaley1  = scaley3*sin(scaley2);

                enemy_x = ObjMove_GetX(enemy);
                enemy_y = ObjMove_GetY(enemy);

	        ObjRender_SetPosition(aura,enemy_x+pX,enemy_y-mY,0);
		ObjRender_SetScaleXYZ(aura,scalex1,scaley1,1);
		ObjPrim_SetVertexColor(aura,0,R*alpha1/255,G*alpha1/255,B*alpha1/255);
		ObjPrim_SetVertexColor(aura,1,R*alpha1/255,G*alpha1/255,B*alpha1/255);
		ObjPrim_SetVertexColor(aura,2,R*alpha1/255,G*alpha1/255,B*alpha1/255);
		ObjPrim_SetVertexColor(aura,3,R*alpha1/255,G*alpha1/255,B*alpha1/255);
		ObjPrim_SetVertexAlpha(aura,0,alpha1);
		ObjPrim_SetVertexAlpha(aura,1,alpha1);
		ObjPrim_SetVertexAlpha(aura,2,alpha1);
		ObjPrim_SetVertexAlpha(aura,3,alpha1);
                if(Obj_IsDeleted(enemy)){break;}
		yield;
	}
	Obj_Delete(aura);
}

//-----------------------------------------------------------------------
// ■ 敵オーラ [th11〜th14] [収束]
//-----------------------------------------------------------------------
task Aura1_2(enemy,time,R,G,B) {

	let aura	= ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let alpha	= 0;
	let scale	= 3.0;

        let enemy_x = ObjMove_GetX(enemy);
        let enemy_y = ObjMove_GetY(enemy);

	LoadTexture(imgaura1);

	ObjRender_SetPosition(aura,enemy_x,enemy_y,0);
	ObjPrim_SetTexture(aura,imgaura1);
	ObjRender_SetBlendType(aura,BLEND_ADD_RGB);
	ObjPrim_SetPrimitiveType(aura,PRIMITIVE_TRIANGLESTRIP);
	ObjRender_SetScaleXYZ(aura,scale,scale,1);
	ObjRender_SetAngleXYZ(aura,0,0,rand(0,360));
	Obj_SetRenderPriorityI(aura,25);
	ObjPrim_SetVertexCount(aura,4);
	ObjPrim_SetVertexPosition(aura,0,-24,-24,0);
	ObjPrim_SetVertexPosition(aura,1,-24, 24,0);
	ObjPrim_SetVertexPosition(aura,2, 24,-24,0);
	ObjPrim_SetVertexPosition(aura,3, 24, 24,0);
	ObjPrim_SetVertexUVT(aura,0, 48,  0);
	ObjPrim_SetVertexUVT(aura,1, 48, 48);
	ObjPrim_SetVertexUVT(aura,2, 96,  0);
	ObjPrim_SetVertexUVT(aura,3, 96, 48);

	loop(time) {
		scale -= 2.0/time;
		alpha += 224/time;

                enemy_x = ObjMove_GetX(enemy);
                enemy_y = ObjMove_GetY(enemy);

	        ObjRender_SetPosition(aura,enemy_x,enemy_y,0);
		ObjRender_SetScaleXYZ(aura,scale,scale,1);
		ObjPrim_SetVertexColor(aura,0,R*alpha/255,G*alpha/255,B*alpha/255);
		ObjPrim_SetVertexColor(aura,1,R*alpha/255,G*alpha/255,B*alpha/255);
		ObjPrim_SetVertexColor(aura,2,R*alpha/255,G*alpha/255,B*alpha/255);
		ObjPrim_SetVertexColor(aura,3,R*alpha/255,G*alpha/255,B*alpha/255);
		ObjPrim_SetVertexAlpha(aura,0,alpha);
		ObjPrim_SetVertexAlpha(aura,1,alpha);
		ObjPrim_SetVertexAlpha(aura,2,alpha);
		ObjPrim_SetVertexAlpha(aura,3,alpha);
                if(Obj_IsDeleted(enemy)){break;}
		yield;
	}
	Obj_Delete(aura);
}

//-----------------------------------------------------------------------
// ■ 敵オーラ [th11〜th14] [周囲の霧]
//-----------------------------------------------------------------------
task Aura2(enemy,time,R,G,B) {

	let aura	= ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let scale1	= 0.0;
	let scale2	= 1.4;
	let scale3	= 0.0;
	let alpha	= 200;

        let enemy_x = ObjMove_GetX(enemy);
        let enemy_y = ObjMove_GetY(enemy);

	LoadTexture(imgaura2);

	ObjRender_SetPosition(aura,enemy_x,enemy_y,0);
	ObjPrim_SetTexture(aura,imgaura2);
	ObjRender_SetBlendType(aura,BLEND_ALPHA);
	ObjPrim_SetPrimitiveType(aura,PRIMITIVE_TRIANGLESTRIP);
	ObjRender_SetScaleXYZ(aura,scale1,scale1,1);
	ObjRender_SetAngleXYZ(aura,0,0,0);
	Obj_SetRenderPriorityI(aura,25);
	ObjPrim_SetVertexCount(aura,4);
	ObjPrim_SetVertexPosition(aura,0,-127,-127,0);
	ObjPrim_SetVertexPosition(aura,1,-127, 127,0);
	ObjPrim_SetVertexPosition(aura,2, 127,-127,0);
	ObjPrim_SetVertexPosition(aura,3, 127, 127,0);
	ObjPrim_SetVertexUVT(aura,0,  1,  1);
	ObjPrim_SetVertexUVT(aura,1,  1,255);
	ObjPrim_SetVertexUVT(aura,2,255,  1);
	ObjPrim_SetVertexUVT(aura,3,255,255);
	ObjPrim_SetVertexColor(aura,0,R,G,B);
	ObjPrim_SetVertexColor(aura,1,R,G,B);
	ObjPrim_SetVertexColor(aura,2,R,G,B);
	ObjPrim_SetVertexColor(aura,3,R,G,B);
	ObjPrim_SetVertexAlpha(aura,0,alpha);
	ObjPrim_SetVertexAlpha(aura,1,alpha);
	ObjPrim_SetVertexAlpha(aura,2,alpha);
	ObjPrim_SetVertexAlpha(aura,3,alpha);

	loop(time) {
		scale3 += 90/time;
		scale1  = scale2*sin(scale3);

                enemy_x = ObjMove_GetX(enemy);
                enemy_y = ObjMove_GetY(enemy);

	        ObjRender_SetPosition(aura,enemy_x,enemy_y,0);
		ObjRender_SetScaleXYZ(aura,scale1,scale1,1);
                if(Obj_IsDeleted(enemy)){break;}
		yield;
	}
	scale1 = scale2;
	while(!Obj_IsDeleted(enemy)) {
                enemy_x = ObjMove_GetX(enemy);
                enemy_y = ObjMove_GetY(enemy);

	        ObjRender_SetPosition(aura,enemy_x,enemy_y,0);
		ObjRender_SetScaleXYZ(aura,scale1,scale1,1);
		yield;
	}
        Obj_Delete(aura);
}
