
let dirCurrent = GetCurrentScriptDirectory();
let BossPosition=[0,0];

@Initialize
{
	BossExplode;
	InitFrame();
	THiScore();
	TScore();
	TGraze();
	TFPS;

	TBossLife();

	TBossTimer();
	GrazeBonus;
}

@MainLoop
{
	if(length(GetEnemyBossObjectID)>0)
	{
	BossPosition[0]=ObjRender_GetX(GetEnemyBossObjectID()[0]);
	BossPosition[1]=ObjRender_GetY(GetEnemyBossObjectID()[0]);
	}
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_START_BOSS_SPELL)
	{
		let path = dirCurrent ~ "System_MagicCircle.txt";
		let id = LoadScript(path);
		StartScript(id);
	}
	case(EV_GAIN_SPELL)
	{
		TMotionBlur();
		let objScene = GetEnemyBossSceneObjectID();
		let score = GetCommonData("SpellCardBonus",10);
		let GA=GetCommonData("GrazeAchieve",0);
		let M=100+GetGraze/GA*100;
		M=floor(M);
		score=floor(score*M/100);
		if(score>GetCommonData("Ori_SpellCardBonus",10)*2)
		{
			score=GetCommonData("Ori_SpellCardBonus",10)*2;
		}
		TGainSpell(score);
	}
}
task TMotionBlur()
{
	//レンダリングターゲットに使用するテクスチャ
	let renderTexture = [GetReservedRenderTargetName(0), GetReservedRenderTargetName(1)];

	//モーションブラーでの描画でまかなえるため、
	//優先度20〜79の通常描画を無効にする。
	SetInvalidRenderPriorityA1(20, 79);

	//現フレームを描画するオブジェクト
	let objCurentFrame = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(objCurentFrame, 80);//優先度80に描画する
	ObjRender_SetPermitCamera(objCurentFrame, false);

	let Alpha=200;
	let BAlpha=Alpha;
	//過去フレーム用オブジェクト
	let objOldFrame = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(objOldFrame, 0);
	ObjRender_SetPermitCamera(objOldFrame, false);
	ObjRender_SetAlpha(objOldFrame, 240);//α値はモーションブラーの強さになります
	Obj_SetVisible(objOldFrame, false);//過去フレーム用なので通常の描画がされないようにします。
	ObjRender_SetScaleXYZ(objOldFrame,1.04,1.04,1);
	ObjRender_SetBlendType(objOldFrame, BLEND_ADD_RGB);
	let frame = 0;
	loop(180)
	{
		let cx=GetCommonData("BossPosition",[0,0])[0];
		let cy=GetCommonData("BossPosition",[0,0])[1];

		let currentFrameTexture = renderTexture[frame % 2];

		//優先度20〜79(STGフレーム全体)をテクスチャに描画する。
		RenderToTextureA1(currentFrameTexture, 20, 79, true);

		if(frame >= 1) 
		{
			//前フレームを現フレームに半透明描画
			//0フレーム目は前フレームがないためこの処理は行わない。
			let oldFrameTexture = renderTexture[(frame - 1) % 2];
			ObjPrim_SetTexture(objOldFrame, oldFrameTexture);
			ObjSprite2D_SetSourceRect(objOldFrame, 32, 16, 416, 464);
			ObjSprite2D_SetDestRect(objOldFrame, -192-112, -224+120, 192-112, 224+120);
			ObjSprite2D_SetDestRect(objOldFrame, -192-(cx-224), -224-(cy-240), 192-(cx-224), 224-(cy-240));
			RenderToTextureB1(currentFrameTexture, objOldFrame, false);
		}

		//現フレーム描画用オブジェクトを設定
		ObjPrim_SetTexture(objCurentFrame, currentFrameTexture);
		ObjSprite2D_SetSourceRect(objCurentFrame, 32, 16, 416, 464);
		ObjSprite2D_SetDestRect(objCurentFrame, 32, 16, 416, 464);

		ObjRender_SetX(objOldFrame,224+112);
		ObjRender_SetY(objOldFrame,240);
		ObjRender_SetX(objOldFrame,cx);
		ObjRender_SetY(objOldFrame,cy);

		ObjRender_SetColor(objOldFrame,1*Alpha,1*Alpha,1*Alpha);
		ObjRender_SetAlpha(objOldFrame,Alpha);

		Alpha-=BAlpha/180;
		frame++;
		
		yield;
	}

	//モーションブラー用オブジェクト削除
	Obj_Delete(objCurentFrame);
	Obj_Delete(objOldFrame);
	ClearInvalidRenderPriority();
}

task TFPS
{
		function CreateTextObject(let mx, let my, let text)
		{
			let obj = ObjText_Create();
			ObjText_SetText(obj, text);
			ObjText_SetFontSize(obj, 14+4);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
			ObjText_SetFontColorBottom(obj, 160, 160, 255);
		//	ObjText_SetFontBorderType(obj, BORDER_FULL);
			ObjText_SetFontBorderType(obj, BORDER_NONE);
			ObjText_SetFontBorderColor(obj,255, 255, 255);
			ObjText_SetFontBorderWidth(obj, 2*0);
			Obj_SetRenderPriorityI(obj, 100);
			ObjRender_SetX(obj, mx);
			ObjRender_SetY(obj, my);

			ObjText_SetFontType(obj,"ＭＳ 明朝");

			return obj;
		}

	let objText10=CreateTextObject(584, 458-18,"");
	while(true)
	{
		ObjRender_SetX(objText10,584);
		let fpslength=5;
		if(GetCurrentFps>=100){fpslength=6;ObjRender_SetX(objText10,574);}
		ObjText_SetText(objText10,vtos("3f",GetCurrentFps)[0..fpslength]);
		yield;
	}
}

task GrazeBonus
{
	let oldGraze=GetGraze;
	loop
	{
		if(oldGraze<GetGraze)
		{
		//	AddScore((GetGraze-oldGraze)*100);
			oldGraze=GetGraze;
		}
		yield;
	}
}

task BossExplode
{
loop
{
	if(GetCommonData("BossDefeat",false))
	{
		yield;
		SetCommonData("BossDefeat",false);
		TExplosion();
		EraseEffect();
	}
	yield;
}

task EraseEffect
{
	let ObjBulletPosition_Array=GetCommonData("ObjBulletPosition_Array",[]);
	ascent(i in 0..length(ObjBulletPosition_Array))
	{
		let color=GetShotDataInfoA1(ObjBulletPosition_Array[i][2],TARGET_ENEMY,INFO_DELAY_COLOR);
		E_Effect(ObjBulletPosition_Array[i][0],ObjBulletPosition_Array[i][1],color);
	}

	task E_Effect(x,y,color)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../img/effect/Marisa_shots.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetVertexPosition(obj, 0, -64, -64, -0);
		ObjPrim_SetVertexPosition(obj, 1, 64, -64, -0);
		ObjPrim_SetVertexPosition(obj, 2, 64, 64, 0);
		ObjPrim_SetVertexPosition(obj, 3, -64, 64, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 256);
		ObjPrim_SetVertexUVT(obj, 1, 128, 256);
		ObjPrim_SetVertexUVT(obj, 2, 128, 384);
		ObjPrim_SetVertexUVT(obj, 3, 0, 384);

		ObjRender_SetPosition(obj,x,y,0);

		let Alpha=0.2;
		let Scale=0;
		let R=color[0];
		let G=color[1];
		let B=color[2];

		let Xangle=rand(0,360);
		let Yangle=rand(0,360);
		let Zangle=rand(0,360);

		loop(75)
		{
			Alpha-=0.2/75;
			Scale+=2/75;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
			yield;
		}
		Obj_Delete(obj);
	}
}

task TExplosion
{
	let MS=30.0;
	let i=0;
	loop(60)
	{
		E_Effect(MS);
		if(i<40){E_Dust(1);}
		if(i<20){E_Dust(0.5);}	
		E_Dust(0.25);
		MS-=30/60;
		i+=1;
		yield;
	}

	task E_Effect(MaxScale)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../img/effect/Marisa_shots.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetVertexPosition(obj, 0, -64, -64, -0);
		ObjPrim_SetVertexPosition(obj, 1, 64, -64, -0);
		ObjPrim_SetVertexPosition(obj, 2, 64, 64, 0);
		ObjPrim_SetVertexPosition(obj, 3, -64, 64, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 256);
		ObjPrim_SetVertexUVT(obj, 1, 128, 256);
		ObjPrim_SetVertexUVT(obj, 2, 128, 384);
		ObjPrim_SetVertexUVT(obj, 3, 0, 384);

		ObjRender_SetPosition(obj,BossPosition[0],BossPosition[1],0);

		let Alpha=0.2;
		let Scale=0;
		let R=255;
		let G=255;
		let B=255;

		let Xangle=rand(0,360);
		let Yangle=rand(0,360);
		let Zangle=rand(0,360);

		loop(30)
		{
			Alpha-=0.2/30;
			Scale+=MaxScale/30;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
			yield;
		}
		Obj_Delete(obj);
	}

	task E_Effect2(MaxScale)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../img/effect/Marisa_shots.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetVertexPosition(obj, 0, -64, -64, -0);
		ObjPrim_SetVertexPosition(obj, 1, 64, -64, -0);
		ObjPrim_SetVertexPosition(obj, 2, 64, 64, 0);
		ObjPrim_SetVertexPosition(obj, 3, -64, 64, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 256);
		ObjPrim_SetVertexUVT(obj, 1, 128, 256);
		ObjPrim_SetVertexUVT(obj, 2, 128, 384);
		ObjPrim_SetVertexUVT(obj, 3, 0, 384);

		ObjRender_SetPosition(obj,BossPosition[0],BossPosition[1],0);

		let Alpha=0.2;
		let Scale=0;
		let Color=HueDifine(rand(0,360));

		let Xangle=rand(0,360);
		let Yangle=rand(0,360);
		let Zangle=rand(0,360);

		loop(30)
		{
			Alpha-=0.2/30;
			Scale+=MaxScale/30;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetColor(obj,Color[0]*Alpha,Color[1]*Alpha,Color[2]*Alpha);
			ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
			yield;
		}
		Obj_Delete(obj);
	}

	task E_Dust(sp)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../img/effect/Marisa_shots.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetVertexPosition(obj, 0, -64, -64, -0);
		ObjPrim_SetVertexPosition(obj, 1, 64, -64, -0);
		ObjPrim_SetVertexPosition(obj, 2, 64, 64, 0);
		ObjPrim_SetVertexPosition(obj, 3, -64, 64, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 256);
		ObjPrim_SetVertexUVT(obj, 1, 128, 256);
		ObjPrim_SetVertexUVT(obj, 2, 128, 384);
		ObjPrim_SetVertexUVT(obj, 3, 0, 384);

		ObjRender_SetPosition(obj,BossPosition[0],BossPosition[1],0);

		let speed=(rand(1,15)*sp);
		let Angle=rand(0,360);
		let Alpha=0.5;
		let Scale=rand(0.25,0.75);
		let Xangle=0;
		let Yangle=0;
		let Zangle=0;
		let XangleRotate=rand(-10,10);
		let YangleRotate=rand(-10,10);
		let ZangleRotate=rand(-10,10);
		let R=255;
		let G=255;
		let B=255;
		loop(45)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(Angle),ObjRender_GetY(obj)+speed*sin(Angle),0);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetAngleX(obj,Xangle);
			ObjRender_SetAngleY(obj,Yangle);
			ObjRender_SetAngleZ(obj,Zangle);
			Alpha-=0.5/45;
			Scale-=0.2/45;
			Xangle+=XangleRotate;
			Yangle+=YangleRotate;
			Zangle+=ZangleRotate;
			yield;
		}
		Obj_Delete(obj);
	}
	task E_Dust2
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../img/effect/Marisa_shots.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetVertexPosition(obj, 0, -64, -64, -0);
		ObjPrim_SetVertexPosition(obj, 1, 64, -64, -0);
		ObjPrim_SetVertexPosition(obj, 2, 64, 64, 0);
		ObjPrim_SetVertexPosition(obj, 3, -64, 64, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 256);
		ObjPrim_SetVertexUVT(obj, 1, 128, 256);
		ObjPrim_SetVertexUVT(obj, 2, 128, 384);
		ObjPrim_SetVertexUVT(obj, 3, 0, 384);

		ObjRender_SetPosition(obj,BossPosition[0],BossPosition[1],0);

		let speed=(rand(1,15));
		let Angle=rand(0,360);
		let Alpha=0.6;
		let Scale=0.2;
		let Zangle=0;
		let ZangleRotate=rand(-10,10);
		let Color=HueDifine(rand(0,360));

		loop(45)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(Angle),ObjRender_GetY(obj)+speed*sin(Angle),0);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetColor(obj,Color[0]*Alpha,Color[1]*Alpha,Color[2]*Alpha);
			ObjRender_SetAngleZ(obj,Zangle);
			Alpha-=0.6/45;
			Scale-=0.2/45;
			Zangle+=ZangleRotate;
			yield;
		}
		Obj_Delete(obj);
	}
}

}
//----------------------------------------------------
//枠外の背景表示
//----------------------------------------------------
function InitFrame()
{
	//let path = GetCurrentScriptDirectory() ~ "img/Default_SystemBackground.png";
	let path = GetCurrentScriptDirectory() ~ "img/Title.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0);
	ObjSprite2D_SetSourceRect(obj, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
	ObjSprite2D_SetDestRect(obj, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}

//----------------------------------------------------
//スコア表示
//----------------------------------------------------
task THiScore()
{
	//Score文字列
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, "High Score");
	ObjText_SetFontSize(objScore, 20);
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 255, 255);
	ObjText_SetFontBorderType(objScore, BORDER_NONE);
	ObjText_SetFontBorderColor(objScore,128, 128, 128);
	ObjText_SetFontBorderWidth(objScore, 0);
	Obj_SetRenderPriority(objScore, 0.01);
	ObjRender_SetX(objScore, 428);
	ObjRender_SetY(objScore, 24);

	//得点
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";
	let count = 10;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 48-4);

	let score2=0;
	while(true)
	{

	if(GetAreaCommonData("TUNING","PlayerCharacter",0)==0)
	{
		score2=GetAreaCommonData("SPELL_RECORD","Reimu_Score",[])[GetCommonData("SpellNumber",9)];
	}
	else if(GetAreaCommonData("TUNING","PlayerCharacter",0)==1)
	{
		score2=GetAreaCommonData("SPELL_RECORD","Marisa_Score",[])[GetCommonData("SpellNumber",9)];
	}

		let score = GetScore();
		//score = max(score,GetAreaCommonData("SCORE","HighScore",1000000));
		score = max(score,score2);

		let listNum = DigitToArray(score, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 428 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 36, 0, (num + 1) * 36, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			if(num!=0 || iObj==9 || score>=10^(10-iObj))
			{
			ObjSpriteList2D_AddVertex(obj);
			}
			if(iObj<1){ObjRender_SetColor(obj,150,255,150);}
			else if(iObj<5){ObjRender_SetColor(obj,255,255,150);}
			else{ObjRender_SetColor(obj,255,255,255);}
		}
		yield;
	}
}

task TScore()
{
	//Score文字列
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, "Expected Score");
	ObjText_SetFontSize(objScore, 20);
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 255, 255);
	ObjText_SetFontBorderType(objScore, BORDER_NONE);
	ObjText_SetFontBorderColor(objScore,128, 128, 128);
	ObjText_SetFontBorderWidth(objScore, 0);
	Obj_SetRenderPriority(objScore, 0.01);
	ObjRender_SetX(objScore, 428);
	ObjRender_SetY(objScore, 80-8);

	//得点
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";
	let count = 10;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 104-8-4);

	let GA=GetCommonData("GrazeAchieve",500);

	while(true)
	{
		let SpellCardBonus=GetCommonData("SpellCardBonus",10);
		let M=100+GetGraze()/GA*100;
		M=floor(M);
		SpellCardBonus=floor(SpellCardBonus*M/100);
		let score = SpellCardBonus;
		score = min(score, GetCommonData("Ori_SpellCardBonus",10)*2);
		let listNum = DigitToArray(score, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 428 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 36, 0, (num + 1) * 36, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			if(num!=0 || iObj==9 || score>=10^(10-iObj))
			{
			ObjSpriteList2D_AddVertex(obj);
			}
			if(iObj<1){ObjRender_SetColor(obj,150,255,150);}
			else if(iObj<5){ObjRender_SetColor(obj,255,255,150);}
			else{ObjRender_SetColor(obj,255,255,255);}
		}
		yield;
	}
}

//----------------------------------------------------
//Graze表示
//----------------------------------------------------
task TGraze()
{
	//Graze文字列
	let objGraze = ObjText_Create();
	ObjText_SetText(objGraze, "Graze");
	ObjText_SetFontSize(objGraze, 20);
	ObjText_SetFontBold(objGraze, true);
	ObjText_SetFontColorTop(objGraze, 255, 255, 255);
	ObjText_SetFontColorBottom(objGraze, 255, 255, 255);
	ObjText_SetFontBorderType(objGraze, BORDER_NONE);
	ObjText_SetFontBorderColor(objGraze,128, 128, 128);
	ObjText_SetFontBorderWidth(objGraze, 0);
	Obj_SetRenderPriority(objGraze, 0.01);
	ObjRender_SetX(objGraze, 428);
	ObjRender_SetY(objGraze, 120);

	//得点
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";
	let count = 10;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 140);

	while(true)
	{
		let graze = GetGraze();
		graze = min(graze, 99999);
		let listNum = DigitToArray(graze, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 428 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 36, 0, (num + 1) * 36, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			if(num!=0 || iObj==9 || graze>=10^(10-iObj))
			{
			ObjSpriteList2D_AddVertex(obj);
			}
			if(iObj<1){ObjRender_SetColor(obj,150,255,150);}
			else if(iObj<5){ObjRender_SetColor(obj,255,255,150);}
			else{ObjRender_SetColor(obj,255,255,255);}
		}
		yield;
	}
}

//----------------------------------------------------
//ボスのライフ表示
//----------------------------------------------------
task TBossLife
{
	let objScene;
	objScene = GetEnemyBossObjectID();
	loop
	{
	if(length(GetEnemyBossObjectID)>0 && GetCommonData("SpecialStage",false)==false && GetCommonData("GaugeInVisible",false)==false)
	{
		if(ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE)!=1)
		{
			if(GetAreaCommonData("TUNING","Setting",[])[3]==1)
			{
				RenderLifeFrame_C();
				RenderLife_C();
			}
			else
			{
				RenderLifeFrame_B();
				RenderLife_B();
			}
			if(GetAreaCommonData("TUNING","Setting",[])[2]==1)
			{
				RenderLifeNum;
			}
			while(length(GetEnemyBossObjectID)>0 && ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE)>0){yield;}
		}
	}
	yield;
	}

	task RenderLifeNum
	{
		let MaxLife=ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE);
		let MaxLifeText=IntToString(MaxLife);
		let DrawX=40;
		let DrawY=30;
		let Alpha=255;

		DrawPosition;
		SetAlpha;

		ascent(i in 0..length(MaxLifeText))
		{
			DrawNum(-4-8*length(MaxLifeText)+8*i,i);
			loop(1){yield;}
		}

		DrawLetter(0,"/");
		loop(1){yield;}

		ascent(i in 0..length(MaxLifeText))
		{
			DrawNum2(44-8*length(MaxLifeText)*0-32+8*i,MaxLifeText[i]);
			loop(1){yield;}
		}
	
		task DrawPosition
		{
			if(GetAreaCommonData("TUNING","Setting",[])[3]==0)
			{
				return;
			}
			while(length(GetEnemyBossObjectID)>0)
			{
				DrawX=ObjRender_GetX(GetEnemyBossObjectID[0]);
				DrawY=ObjRender_GetY(GetEnemyBossObjectID[0])+32;
				yield;
			}
		}

		task SetAlpha
		{
			while(length(GetEnemyBossObjectID)>0)
			{
				if(GetAreaCommonData("TUNING","Setting",[])[3]==0)
				{
					if(GetPlayerY<=128)
					{		
						Alpha=(GetPlayerY/128)*255;
					}
					else{Alpha=255;}
				}
				else
				{
					let Dis=((ObjRender_GetY(GetEnemyBossObjectID()[0])-GetPlayerY)^2+(ObjRender_GetX(GetEnemyBossObjectID()[0])-GetPlayerX)^2)^0.5;
					if(Dis<100)
					{
						Alpha=25+230*Dis/100;
					}
					else
					{
						Alpha=255;
					}
				}
				yield;
			}
		}	
		task DrawNum(dx,num)
		{
			let Life=ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE);
			let LifeText=IntToString(Life);
			let obj = ObjText_Create();
			ObjText_SetText(obj, LifeText[num]);
			ObjText_SetFontSize(obj, 12);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
//			ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
			ObjText_SetFontBorderType(obj, BORDER_NONE);
			ObjText_SetFontBorderColor(obj,0, 255, 0);
			ObjText_SetFontBorderWidth(obj, 0);
			Obj_SetRenderPriorityI(obj, 72);
			ObjRender_SetX(obj, DrawX+dx);
			ObjRender_SetY(obj, DrawY);
			//ObjText_SetFontType(obj,"ＭＳ 明朝");

			ObjText_SetMaxWidth(obj,360);
			let scale=3;

			while(length(GetEnemyBossObjectID)>0)
			{
				if(scale>1.05)
				{
					scale-=2/15;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				}
				LifeText=IntToString(ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE));
				while(length(LifeText)<length(MaxLifeText))
				{
					LifeText=" "~LifeText;
				}
				ObjText_SetText(obj, LifeText[num]);

				ObjRender_SetAlpha(obj,Alpha);
				ObjRender_SetX(obj, DrawX+dx);
				ObjRender_SetY(obj, DrawY);
				yield;
			}
			Obj_Delete(obj);
		}

		task DrawNum2(dx,number)
		{
			let obj = ObjText_Create();
			ObjText_SetText(obj, number);
			ObjText_SetFontSize(obj, 12);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
//			ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
			ObjText_SetFontBorderType(obj, BORDER_NONE);
			ObjText_SetFontBorderColor(obj,0, 255, 0);
			ObjText_SetFontBorderWidth(obj, 0);
			Obj_SetRenderPriorityI(obj, 72);
			ObjRender_SetX(obj, DrawX+dx);
			ObjRender_SetY(obj, DrawY);
			//ObjText_SetFontType(obj,"ＭＳ 明朝");

			ObjText_SetMaxWidth(obj,360);
			let scale=3;
			while(length(GetEnemyBossObjectID)>0)
			{
				if(scale>1.05)
				{
					scale-=2/15;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				}
				ObjRender_SetAlpha(obj,Alpha);
				ObjRender_SetX(obj, DrawX+dx);
				ObjRender_SetY(obj, DrawY);
				yield;
			}
			Obj_Delete(obj);
		}

		task DrawLetter(dx,letter)
		{
//			let color=[255,255,255];
//			color=SetSpellCardColor(Name);

			let obj = ObjText_Create();
			ObjText_SetText(obj,letter);
			ObjText_SetFontSize(obj, 12);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
//			ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
			ObjText_SetFontBorderType(obj, BORDER_NONE);
			ObjText_SetFontBorderColor(obj,0, 255, 0);
			ObjText_SetFontBorderWidth(obj, 0);
			Obj_SetRenderPriorityI(obj, 72);
			ObjRender_SetX(obj, DrawX+dx);
			ObjRender_SetY(obj, DrawY);
			//ObjText_SetFontType(obj,"ＭＳ 明朝");

			ObjText_SetMaxWidth(obj,360);
			let scale=3;

			while(length(GetEnemyBossObjectID)>0)
			{
				if(scale>1.05)
				{
					scale-=2/15;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				}			
				ObjRender_SetAlpha(obj,Alpha);
				ObjRender_SetX(obj, DrawX+dx);
				ObjRender_SetY(obj, DrawY);
				yield;
			}
			Obj_Delete(obj);
		}
	}

	task RenderLife_B
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"img/ber2.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,20);
	//	ObjRender_SetAngleZ(obj,180);
		ObjPrim_SetVertexPosition(obj, 0, -0, -2, -0);
		ObjPrim_SetVertexPosition(obj, 1, 388, -2, -0);
		ObjPrim_SetVertexPosition(obj, 2, 388, 2, 0);
		ObjPrim_SetVertexPosition(obj, 3, -0, 2, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 12);
		ObjPrim_SetVertexUVT(obj, 1, 128, 12);
		ObjPrim_SetVertexUVT(obj, 2, 128, 16);
		ObjPrim_SetVertexUVT(obj, 3, 0, 16);
		ObjRender_SetPosition(obj,0,25,0);

		let obj2 = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj2, GetCurrentScriptDirectory~"img/ber2.png");
		ObjPrim_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj2, 4);
	//	ObjRender_SetBlendType(obj2, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj2,20);
		ObjPrim_SetVertexPosition(obj2, 0, -0, -1, -0);
		ObjPrim_SetVertexPosition(obj2, 1, 384, -1, -0);
		ObjPrim_SetVertexPosition(obj2, 2, 384, 1, 0);
		ObjPrim_SetVertexPosition(obj2, 3, -0, 1, 0);

		ObjPrim_SetVertexUVT(obj2, 0, 0, 12);
		ObjPrim_SetVertexUVT(obj2, 1, 128, 12);
		ObjPrim_SetVertexUVT(obj2, 2, 128, 16);
		ObjPrim_SetVertexUVT(obj2, 3, 0, 16);
		ObjRender_SetPosition(obj2,0,448-1,0);

		let Color=[255,50,50];
		let Color2=[255,255,255];
		let Alpha=1;
		let AR_Angle=0;
		let AlphaRate=0.75+0.25*cos(AR_Angle);
		let HueCount=0;
		let RingRate=0;
		let MaxLife=ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE);
		while(length(GetEnemyBossObjectID)>0)
		{
			if(ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE)<=0){break;}

			if(GetPlayerY<=128)
			{		
				Alpha=(GetPlayerY/128);
			}
			else{Alpha=1;}

			if(RingRate<1){RingRate+=1/60;}

			let LifeLeft=ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE)/(MaxLife/360)*RingRate;

			let H_Color=HueDifine(HueCount);
			ObjRender_SetColor(obj,(Color[0]-H_Color[0]/4)*Alpha,(Color[1]-H_Color[1]/4)*Alpha,(Color[2]-H_Color[2]/4)*Alpha);
			HueCount+=3;

			ObjRender_SetScaleX(obj,LifeLeft/360);

			ObjRender_SetScaleX(obj2,LifeLeft/360);
			ObjRender_SetColor(obj2,(Color2[0]-H_Color[0]/4)*Alpha,(Color2[1]-H_Color[1]/4)*Alpha,(Color2[2]-H_Color[2]/4)*Alpha);
			yield;
		}
		Obj_Delete(obj);
		Obj_Delete(obj2);
	}

	task RenderLifeFrame_B
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"img/ber2.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,20);
		ObjRender_SetPosition(obj,0,25,0);

		ObjPrim_SetVertexPosition(obj, 0, -0, -2, -0);
		ObjPrim_SetVertexPosition(obj, 1, 384, -2, -0);
		ObjPrim_SetVertexPosition(obj, 2, 384, 2, 0);
		ObjPrim_SetVertexPosition(obj, 3, -0, 2, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 4);
		ObjPrim_SetVertexUVT(obj, 1, 128, 4);
		ObjPrim_SetVertexUVT(obj, 2, 128, 12);
		ObjPrim_SetVertexUVT(obj, 3, 0, 12);

		let Alpha=1;
		let Color=[10,10,10];
		let RingRate=0;
		while(length(GetEnemyBossObjectID)>0)
		{
			if(ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE)<=0){break;}

			if(GetPlayerY<=128)
			{		
				Alpha=(GetPlayerY/128);
			}
			else{Alpha=1;}

			if(RingRate<1){RingRate+=1/60;}
			let LifeLeft=360*RingRate;

			ObjRender_SetColor(obj,Color[0]*Alpha,Color[1]*Alpha,Color[2]*Alpha);
			ObjRender_SetScaleX(obj,LifeLeft/360);

			yield;
		}
		Obj_Delete(obj);
	}
	task RenderLife_C
	{
		let Vertex=64;
		let Radius=[50,55];

		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"img/ber2.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(obj, Vertex);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,20);
		ObjRender_SetAngleZ(obj,180);

		let obj2 = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj2, GetCurrentScriptDirectory~"img/ber2.png");
		ObjPrim_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj2, 4);
		ObjRender_SetBlendType(obj2, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj2,20);
		ObjPrim_SetVertexPosition(obj2, 0, -0, -1, -0);
		ObjPrim_SetVertexPosition(obj2, 1, 384, -1, -0);
		ObjPrim_SetVertexPosition(obj2, 2, 384, 1, 0);
		ObjPrim_SetVertexPosition(obj2, 3, -0, 1, 0);

		ObjPrim_SetVertexUVT(obj2, 0, 0, 12);
		ObjPrim_SetVertexUVT(obj2, 1, 128, 12);
		ObjPrim_SetVertexUVT(obj2, 2, 128, 16);
		ObjPrim_SetVertexUVT(obj2, 3, 0, 16);
		ObjRender_SetPosition(obj2,0,448-1,0);

		ascent(i in 0..Vertex)
		{
			ObjPrim_SetVertexPosition(obj, i, Radius[i%2]*cos(360/(Vertex-1)*i), Radius[i%2]*sin(360/(Vertex-1)*i),0);
		}
		ascent(i in 0..Vertex)
		{	
			ObjPrim_SetVertexUVT(obj, i,  0+128/(Vertex)*i,  0+4*(i%2));
		}

		let Color=[255,50,50];
		let Color2=[255,255,255];
		let Alpha=1;
		let AR_Angle=0;
		let AlphaRate=0.75+0.25*cos(AR_Angle);
		let HueCount=0;
		let RingRate=0;
		let MaxLife=ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE);
		while(length(GetEnemyBossObjectID)>0)
		{
			if(ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE)<=0){break;}
			let Dis=((ObjRender_GetY(GetEnemyBossObjectID()[0])-GetPlayerY)^2+(ObjRender_GetX(GetEnemyBossObjectID()[0])-GetPlayerX)^2)^0.5;
			if(Dis<100)
			{
				Alpha=0.1+0.9*Dis/100;
			}
			else
			{
				Alpha=1;
			}
			if(RingRate<1){RingRate+=1/60;}
			let LifeLeft=ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE)/(MaxLife/360)*RingRate;
			let LifeAngle=LifeLeft/(Vertex-2);
			ascent(i in 0..Vertex)
			{
				alternative(i)
				case(0, 1){ObjPrim_SetVertexPosition(obj,i,Radius[i%2]*sin(0),Radius[i%2]*cos(0),0); }
				case(Vertex-2, Vertex-1){ObjPrim_SetVertexPosition(obj,i,Radius[i%2]*sin(LifeLeft),Radius[i%2]*cos(LifeLeft),0); }
				others{ObjPrim_SetVertexPosition(obj,i,Radius[i%2]*sin(LifeAngle*i),Radius[i%2]*cos(LifeAngle*i),0);}			
			}
			ObjRender_SetPosition(obj,ObjRender_GetX(GetEnemyBossObjectID()[0]),ObjRender_GetY(GetEnemyBossObjectID()[0]),0);
			AR_Angle+=2;
			AlphaRate=0.75+0.25*cos(AR_Angle);
			Alpha*=AlphaRate;
			let H_Color=HueDifine(HueCount);
			ObjRender_SetColor(obj,(Color[0]-H_Color[0]/4)*Alpha,(Color[1]-H_Color[1]/4)*Alpha,(Color[2]-H_Color[2]/4)*Alpha);
			HueCount+=3;

			ObjRender_SetScaleX(obj2,LifeLeft/360);
			ObjRender_SetColor(obj2,(Color2[0]-H_Color[0]/4)*Alpha,(Color2[1]-H_Color[1]/4)*Alpha,(Color2[2]-H_Color[2]/4)*Alpha);
			yield;
		}
		Obj_Delete(obj);
		Obj_Delete(obj2);
	}

	task RenderLifeFrame_C
	{
		let Vertex=64;
		let Radius=[49,56];

		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"img/ber2.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(obj, Vertex);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,20);
		ObjRender_SetAngleZ(obj,180);

		ascent(i in 0..Vertex)
		{
			ObjPrim_SetVertexPosition(obj, i, Radius[i%2]*cos(360/(Vertex-1)*i), Radius[i%2]*sin(360/(Vertex-1)*i),0);
		}
		ascent(i in 0..Vertex)
		{	
			ObjPrim_SetVertexUVT(obj, i,  0+128/(Vertex)*i,  5+6*(i%2));
		}

		let Alpha=1;
		let Color=[10,10,10];
		let RingRate=0;
		while(length(GetEnemyBossObjectID)>0)
		{
			if(ObjEnemy_GetInfo(GetEnemyBossObjectID()[0],INFO_LIFE)<=0){break;}
			let Dis=((ObjRender_GetY(GetEnemyBossObjectID()[0])-GetPlayerY)^2+(ObjRender_GetX(GetEnemyBossObjectID()[0])-GetPlayerX)^2)^0.5;
			if(Dis<100)
			{
				Alpha=1*Dis/100;
			}
			else
			{
				Alpha=1;
			}
			if(RingRate<1){RingRate+=1/60;}
			let LifeLeft=360*RingRate;
			let LifeAngle=LifeLeft/(Vertex-2);
			ascent(i in 0..Vertex)
			{
				alternative(i)
				case(0, 1){ObjPrim_SetVertexPosition(obj,i,Radius[i%2]*sin(0),Radius[i%2]*cos(0),0); }
				case(Vertex-2, Vertex-1){ObjPrim_SetVertexPosition(obj,i,Radius[i%2]*sin(LifeLeft),Radius[i%2]*cos(LifeLeft),0); }
				others{ObjPrim_SetVertexPosition(obj,i,Radius[i%2]*sin(LifeAngle*i),Radius[i%2]*cos(LifeAngle*i),0);}			
			}
			ObjRender_SetPosition(obj,ObjRender_GetX(GetEnemyBossObjectID()[0]),ObjRender_GetY(GetEnemyBossObjectID()[0]),0);
			ObjRender_SetColor(obj,Color[0]*Alpha,Color[1]*Alpha,Color[2]*Alpha);
			yield;
		}
		Obj_Delete(obj);
	}
}

//----------------------------------------------------
//タイマー表示
//----------------------------------------------------
task TBossTimer
{
	let OriTime=ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(), INFO_TIMERF);
	let Time=OriTime;
	let str_SCB=IntToString(Time);
	loop
	{
	OriTime=ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(), INFO_TIMERF);
	Time=OriTime;
	str_SCB=IntToString(Time);
	if(length(GetEnemyBossObjectID)>0 && GetCommonData("SpecialStage",false)==false)
	{
		Time=ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(), INFO_TIMERF)*100/60;
		if(Time>=10000){Time=9999;}
		str_SCB=IntToString(Time);
		if(OriTime>0)
		{
		ascent(i in 0..length(str_SCB))
		{
			DrawNum(198-168-7*length(str_SCB)+7*i,11.5,i);
			loop(1){yield;}
		}
		while(length(GetEnemyBossObjectID)>0)
		{
			Time=ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(), INFO_TIMERF)*100/60;
			if(Time>=10000){Time=9999;}

			str_SCB=IntToString(Time);
			while(length(str_SCB)<4)
			{
				str_SCB=IntToString(0)~str_SCB
			}
			yield;
		}
		}
	}
	yield;
	}
		task DrawNum(x,y,number)
		{
			let obj = ObjText_Create();
			ObjText_SetText(obj, str_SCB[number]);
			ObjText_SetFontSize(obj, 10);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
//			ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
			ObjText_SetFontBorderType(obj, BORDER_NONE);
			ObjText_SetFontBorderColor(obj,0, 255, 0);
			ObjText_SetFontBorderWidth(obj, 0);
			Obj_SetRenderPriorityI(obj, 72);
			ObjRender_SetX(obj,16+x);
			ObjRender_SetY(obj, y);
			//ObjText_SetFontType(obj,"ＭＳ 明朝");

			ObjText_SetMaxWidth(obj,360);
			let Alpha=255;
			let scale=3;

			if(number<2)
			{
				ObjText_SetFontSize(obj, 20);
				ObjRender_SetX(obj,16+x-16+7*number);
				ObjRender_SetY(obj, y-9.0);
			}

			loop(15)
			{
				scale-=2/15;
				ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				if(GetPlayerY<=160)
				{		
					Alpha=(GetPlayerY/160)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			while(length(GetEnemyBossObjectID)>0)
			{
				ObjText_SetText(obj, str_SCB[number]);
				if(GetPlayerY<=160)
				{		
				Alpha=(GetPlayerY/160)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			Obj_Delete(obj);
		}

	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.75);
	ObjRender_SetY(obj, 0);
	let count = 2;

	let objScene = ID_INVALID;
	loop
	{
		objScene = GetEnemyBossSceneObjectID();
		ObjSpriteList2D_ClearVertexCount(obj);
		if(objScene != ID_INVALID)
		{
			RenderTimer();
		}
		yield;
	}

	function RenderTimer()
	{
		let timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER);
		timer = min(timer, 99);
		let listNum = DigitToArray(timer, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 352 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 36, 0, (num + 1) * 36, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}

}

//----------------------------------------------------
//スペルカード取得表示
//----------------------------------------------------
task TGainSpell(score)
{
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Spell Card Bonus!");
	ObjText_SetFontSize(objText, 32);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 128, 128, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,255, 255, 255);
	ObjText_SetFontBorderWidth(objText, 1);
	Obj_SetRenderPriority(objText, 0.6);
	ObjRender_SetX(objText, 32);
	ObjRender_SetY(objText, 98);

	let strScore = "+" ~ IntToString(score);
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, strScore);
	ObjText_SetFontSize(objScore, 32);
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 128, 128);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,255, 255, 255);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.6);
	ObjRender_SetX(objScore, 180);
	ObjRender_SetY(objScore, 140);

	loop(180)
	{
		yield;
	}
	Obj_Delete(objText);
	Obj_Delete(objScore);
}

//----------------------------------------------------
//ユーティリティ
//----------------------------------------------------
function DigitToArray(let digit,let count)
{
	let res = [];
	digit = truncate(digit);

	loop
	{
		let tnum = truncate(digit % 10);
		digit /= 10;
		res = [tnum] ~ res;
		if(truncate(digit) == 0){break;}
	}

	loop(max(0, count - length(res)))
	{
		res = [0] ~ res;
	}

	return res;
}

function HueDifine(HueCount)
{
let ColorRed=0;
let ColorGreen=0;
let ColorBlue=0;
let MinColor=0;
while(HueCount>360){HueCount-=360;}
while(HueCount<=0){HueCount+=360;}
	if(0<HueCount && HueCount<=60)
	{
		ColorRed=255;
		ColorGreen=255*(HueCount)/60;
		ColorBlue=0;
	}
	else if(HueCount<=120)
	{
		ColorRed=255*(120-HueCount)/60;
		ColorGreen=255;
		ColorBlue=0;
	}
	else if(HueCount<=180)
	{
		ColorRed=0;
		ColorGreen=255;
		ColorBlue=255*(HueCount-120)/60;
	}
	else if(HueCount<=240)
	{
		ColorRed=0;
		ColorGreen=255*(240-HueCount)/60;
		ColorBlue=255;
	}
	else if(HueCount<=300)
	{
		ColorRed=255*(HueCount-240)/60;
		ColorGreen=0;
		ColorBlue=255;
	}
	else if(HueCount<=360)
	{
		ColorRed=255;
		ColorGreen=0;
		ColorBlue=255*(360-HueCount)/60;
	}
	return([ColorRed,ColorGreen,ColorBlue]);
}