#include "../../functions/functions_boss.txt"
#include "../../functions/functions_talk.txt"
#include "../include.txt"

let SpritePathBoss = GetCurrentScriptDirectory ~ "./img/face/face.png";
let IsTimeStop = false;

task TBackground
	{
	let current = GetCurrentScriptDirectory ~ "img/";
	TSpellBack;
	task TSpellBack
		{
		let spellA1 = 0;
		let spellA2 = 0;
	
		let vertexcount1 = 15;
		vertexcount1*=2;
		let mov = 0;
		let timeS = false;
	
		let back1 = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetPrimitiveType(back1, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetTexture(back1, GetCurrentScriptDirectory ~ "img/Back_Fire_1.png");
		Obj_SetRenderPriority(back1, 0.26);
		ObjPrim_SetVertexCount(back1, vertexcount1);

		let mov2 = 0.5;
		let back2 = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetPrimitiveType(back2, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetTexture(back2, GetCurrentScriptDirectory ~ "img/Back_Fire_2.png");
		Obj_SetRenderPriority(back2, 0.26);
		ObjPrim_SetVertexCount(back2, vertexcount1);
		ObjRender_SetBlendType(back2,BLEND_ADD_ARGB);
	
		let rate = 0.75;
		ascent(i in 0..vertexcount1/2)
			{
			let i1 = i*2;
			let x = -8+i1*(GetStgFrameWidth+16)/(vertexcount1*0.5);

			ObjPrim_SetVertexPosition(back1,i1+0,x,-8,0);
			ObjPrim_SetVertexColor(back1,i1+0,175*rate,105*rate,105*rate);
			ObjPrim_SetVertexPosition(back1,i1+1,x,GetStgFrameHeight+8,0);
			ObjPrim_SetVertexColor(back1,i1+1,255*0.925,255*0.925,255*0.925);
	
			ObjPrim_SetVertexPosition(back2,i1+0,x,-8,0);
			ObjPrim_SetVertexColor(back2,i1+0,255,155,125);
			ObjPrim_SetVertexPosition(back2,i1+1,x,GetStgFrameHeight+8,0);
			}
		let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj1,GetCurrentScriptDirectory ~ "img/Back_Flag.png");
		ObjSprite2D_SetSourceRect(obj1,0,0,640,480);
		ObjSprite2D_SetDestRect(obj1,-8,-8,GetStgFrameWidth+8,GetStgFrameHeight+8);
		Obj_SetRenderPriority(obj1, 0.25);
	
		let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj2,GetCurrentScriptDirectory ~ "img/Face/Face.png");
		ObjSprite2D_SetSourceRect(obj2,0,0,300,415);
		ObjRender_SetPosition(obj2,GetStgFrameWidth/2,GetStgFrameHeight/2+50,0);
		Obj_SetRenderPriority(obj2, 0.26);
		ObjRender_SetColorHSV(obj2,0,0,0);
		ObjRender_SetScaleXYZ(obj2,-1.175,1.175,0);
		ObjSprite2D_SetDestCenter(obj2);

		let spellA3 = 180-40;
		while(!Obj_IsDeleted(objEnemy))
			{
			if(timeS != IsTimeStop)
				{
				timeS = IsTimeStop;
				}
			if(spellA1 < 1)
				{
				Obj_SetVisible(back2,true);
				Obj_SetVisible(obj2,true);
				spellA1 += 1/30;
				}
			else if(spellA1 >= 1 && spellA2 < 1)
				{
				spellA2 += 1/30;
				}
			if(timeS == false)
				{
				mov+=1.25;
				}
			spellA3+=1;
			ascent(i in 0..vertexcount1/2)
				{
				let indexvert = i*2;
				let angle = 150/(vertexcount1/2-1)*i+30/2+180;
				ObjPrim_SetVertexUVT(back1, indexvert, 512/(vertexcount1/2-1)*i, 0+mov);
				ObjPrim_SetVertexUVT(back1, indexvert+1, 512/(vertexcount1/2-1)*i, 256+mov);
		
				ObjPrim_SetVertexUVT(back2, indexvert, 512/(vertexcount1/2-1)*i, 0+mov*mov2);
				ObjPrim_SetVertexUVT(back2, indexvert+1, 512/(vertexcount1/2-1)*i, 256+mov*mov2);
				}
			ObjRender_SetAlpha(back1,spellA1*155*(0.815+cos(spellA3)*0.1));
			ObjRender_SetAlpha(obj1,spellA1*255);
			ObjRender_SetAlpha(back2,spellA1*155*(0.815+cos(spellA3)*0.1));
			ObjRender_SetAlpha(obj2,spellA2*255);
			yield;
			}
		Obj_Delete(obj1);
		Obj_Delete(back1);
		Obj_Delete(obj2);
		Obj_Delete(back2);
		}
	}

task ObjEnemy_Render
{
	CreateEnemyIcon(objEnemy);	
	let img = SpritePathBoss;
	ObjPrim_SetTexture(objEnemy,img);
	Obj_SetRenderPriority(objEnemy,0.33);

	ObjSprite2D_SetSourceRect(objEnemy,0,0,300,415);
	ObjRender_SetScaleXYZ(objEnemy,0.33,0.33,0);
	ObjSprite2D_SetDestCenter(objEnemy);
}