#include"./../Functions/EventList.txt"

let dirCurrent = GetCurrentScriptDirectory();
let GCSD = GetCurrentScriptDirectory();
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let exlife = 0;
let pathHealth = dirCurrent ~ "img/lifebar.png";
@Initialize
{
	SetPauseScriptPath(dirCurrent ~ "Default_Pause.txt");
	SetEndSceneScriptPath(dirCurrent ~"Default_EndScene.txt");
	InitFrame();
	TScore();
	TGraze();
	TPlayerLife();
	TPlayerSpell();
	TCurrentFps();
	TReplayFps();
	InstallFont(dirCurrent ~ "tech.tff");
}

@MainLoop
{
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_START_BOSS_SPELL)
	{
		let path = dirCurrent ~ "Default_System_MagicCircle.txt";
		let id = LoadScript(path);
		StartScript(id);
		//DrawScore;
	}
	case(EV_GAIN_SPELL)
	{
		let objScene = GetEnemyBossSceneObjectID();
		let score = ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE);
		TGainSpell(score);
	}
	case(EV_SPELL_FAILED)
	{
		TFailSpell;
	}
}

//----------------------------------------------------

task DrawScore{ // Draw score text
	Score;
	BonusText;
	task Score{
		let objText = ObjText_Create();
		let alpha = 0;
		let c = 0;
		ObjText_SetFontSize(objText, 10);
		ObjText_SetFontColorTop(objText,0,0,0);//255,255,255);
		ObjText_SetFontColorBottom(objText,0,0,0);//255,255/2,255);
		ObjText_SetFontBorderType(objText, BORDER_FULL);
		ObjText_SetFontBorderColor(objText,255,255,255);//128,0,192);
		ObjText_SetFontBorderWidth(objText, 2);
		ObjRender_SetPosition(objText,215,43,0);
			while(GetCommonData("IsSpell",false)==true && !Obj_IsDeleted(GetEnemyBossSceneObjectID())){
			if(c>150){
			if(GetPlayerY>100 && alpha<255){alpha+=10;}
			if(GetPlayerY<=100 && alpha>100){alpha-=10;}
			}
			if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID,INFO_PLAYER_SHOOTDOWN_COUNT)==0 && ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID,INFO_PLAYER_SPELL_COUNT)==0 ){
			ObjText_SetText(objText,IntToString(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID,INFO_SPELL_SCORE)));
			}
			else{
			ObjText_SetText(objText,"Failed");
			}
			ObjRender_SetAlpha(objText,alpha);
			c++;
			yield;
			}
			Obj_Delete(objText);
		}
		task BonusText{
		let objText = ObjText_Create();
		let alpha = 0;
		let c = 0;
		ObjText_SetText(objText,"Bonus :");
		ObjText_SetFontSize(objText, 10);
		ObjText_SetFontColorTop(objText,0,0,0);//255,255,255);
		ObjText_SetFontColorBottom(objText,0,0,0);//255,255/2,255);
		ObjText_SetFontBorderType(objText, BORDER_FULL);
		ObjText_SetFontBorderColor(objText,255,255,255);//128,0,192);
		ObjText_SetFontBorderWidth(objText, 2);
		ObjRender_SetPosition(objText,165,43,0);
			while(GetCommonData("IsSpell",false)==true && !Obj_IsDeleted(GetEnemyBossSceneObjectID())){
			if(c>150){
			if(GetPlayerY>100 && alpha<255){alpha+=10;}
			if(GetPlayerY<=100 && alpha>100){alpha-=10;}
			}
			ObjRender_SetAlpha(objText,alpha);
			c++;
			yield;
			}
			Obj_Delete(objText);
		}
	}

	task TContinue{
	DrawText(421,250,0);
	DrawText(528,251,1);
			task DrawText(px,py,type){
			let objText = ObjText_Create();
			ObjText_SetFontSize(objText, 15);
			ObjText_SetFontBold(objText, true);
			ObjText_SetFontColorTop(objText, 0, 0, 0);
			ObjText_SetFontColorBottom(objText, 0, 0, 0);
			ObjText_SetFontBorderType(objText, BORDER_FULL);
			ObjText_SetFontBorderColor(objText,192, 0, 192);
			ObjText_SetFontBorderWidth(objText, 2);
			Obj_SetRenderPriority(objText, 1);
			ObjRender_SetX(objText, px);
			ObjRender_SetY(objText, py);
				while(!Obj_IsDeleted(objText)){
				if(type==0){ObjText_SetText(objText, "Continue :");}
				if(type==1){ObjText_SetText(objText, IntToString(exlife));}
				yield;
				}
		}
	}
//----------------------------------------------------

task TExtend{
	DrawText(420,225,0);
	DrawText(528,226,1);
	DrawText(543,226,2);
		task DrawText(px,py,type){
			let objText = ObjText_Create();
			ObjText_SetFontSize(objText, 15);
			ObjText_SetFontBold(objText, true);
			ObjText_SetFontColorTop(objText, 0, 0, 0);
			ObjText_SetFontColorBottom(objText, 0, 0, 0);
			ObjText_SetFontBorderType(objText, BORDER_FULL);
			ObjText_SetFontBorderColor(objText,192, 0, 128);
			ObjText_SetFontBorderWidth(objText, 2);
			Obj_SetRenderPriority(objText, 1);
			ObjRender_SetX(objText, px);
			ObjRender_SetY(objText, py);
				while(!Obj_IsDeleted(objText)){
				if(type==0){ObjText_SetText(objText, "Next Life :");}
				let piece = GetCommonData("Piece",0);
				let ptext = IntToString(piece);
				if(type==1){
				ObjText_SetText(objText, ptext);
				}				
				if(type==2){
				ObjText_SetText(objText, "/4");
				}
				yield;
				}
			}
	}

function InitFrame()
{
	StgFrame;
	function StgFrame
	{
		let path = GetCurrentScriptDirectory() ~ "img/mitori_frame.png";
		let path2 = GetCurrentScriptDirectory() ~ "img/diff.png";
		Border;
		Difficulty;
		function Border
		{
			let obj = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjPrim_SetTexture(obj, path);
			Obj_SetRenderPriority(obj, 1);
			ObjSprite2D_SetSourceRect(obj, 0, 0, 640, 480);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetPosition(obj, 320, 240, 0);
			ObjRender_SetScaleXYZ(obj,1,1,0);
		}
		function Difficulty
		{
			let obj = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjPrim_SetTexture(obj, path2);
			Obj_SetRenderPriority(obj, 2);
			ObjSprite2D_SetSourceRect(obj, 0, 0, 85, 16);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetBlendType(obj,BLEND_ALPHA);
			ObjRender_SetScaleXYZ(obj,1.1,1.1,0);
			ObjRender_SetPosition(obj, 32 + 384 + 115, 30, 0);
			ObjRender_SetAlpha(obj,255);
		}
	}
	function Overused{
	let path = GetCurrentScriptDirectory() ~ "img/Overused.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 1);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 64);
	ObjSprite2D_SetDestRect(obj, 0, 0, 256, 64);
	ObjRender_SetAlpha(obj,192);
	ObjRender_SetPosition(obj,stgx+115,stgy+100,0);
	ObjRender_SetScaleXYZ(obj,1.65,1.65,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	}
	function AllStars{
	let path = GetCurrentScriptDirectory() ~ "img/Allstars.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 1);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 64);
	ObjSprite2D_SetDestRect(obj, 0, 0, 256, 64);
	ObjRender_SetAlpha(obj,192);
	ObjRender_SetPosition(obj,stgx+165,stgy+175,0);
	ObjRender_SetScaleXYZ(obj,1.35,1.35,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	}
}

//----------------------------------------------------
//スコア表示
//----------------------------------------------------
task TScore()
{
			let text=ObjPrim_Create(OBJ_SPRITE_2D);
			let img=GetCurrentScriptDirectory()~"img/front001.png";
			ObjPrim_SetTexture(text,img);
			ObjSprite2D_SetSourceRect(text,256,18,300,36);
			ObjSprite2D_SetDestCenter(text);
			ObjRender_SetBlendType(text,BLEND_ALPHA);
			ObjRender_SetScaleXYZ(text,1,1,0);
			Obj_SetRenderPriority(text,2);
			ObjRender_SetPosition(text,441,78,0);

	let pathDigit = GetCurrentScriptDirectory() ~ "img/front00.png";
	let count = 11;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 2);
	ObjRender_SetY(obj, 58);
	//ObjRender_SetColor(obj,0,0,0);

	while(true)
	{
		let score = GetScore();
		score = min(score, 999999999999);
		let listNum = DigitToArray(score, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 498 + iObj * 12);
			ObjSpriteList2D_SetSourceRect(obj, 544+num * 16, 161, 544+(num + 1) * 16, 179);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 14, 14*1.4);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}

task TGraze()
{
			let text=ObjPrim_Create(OBJ_SPRITE_2D);
			let img=GetCurrentScriptDirectory()~"img/front001.png";
			ObjPrim_SetTexture(text,img);
			ObjSprite2D_SetSourceRect(text,348,18,394,36);
			ObjSprite2D_SetDestCenter(text);
			ObjRender_SetBlendType(text,BLEND_ALPHA);
			ObjRender_SetScaleXYZ(text,1,1,0);
			Obj_SetRenderPriority(text,2);
			ObjRender_SetPosition(text,341,190,0);

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

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 2);
	ObjRender_SetY(obj, 224);
	ObjRender_SetScaleXYZ(obj,0.9,0.9,0);
	ObjRender_SetColor(obj,256,256,256);
	//ObjRender_SetPosition(text,341,190,0);
	while(true)
	{
		let graze = GetGraze();
		graze = min(graze, 99999);
		let listNum = DigitToArray(graze, count);
		count = length(listNum);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 500 + iObj * 12);
			ObjSpriteList2D_SetSourceRect(obj, 544+num * 16, 161, 544+(num + 1) * 16, 179);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 14, 14*1.5);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}


//----------------------------------------------------
//残機表示
//----------------------------------------------------
task TPlayerLife
{
	//TText;
	ascent(i in 0..8){
	EmptyLife(stgx+315+i*17);
	RealLife(stgx+315+i*17,i);
	}
		task EmptyLife(px){
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		let img=GetCurrentScriptDirectory()~"img/front00.png";
		ObjPrim_SetTexture(obj,img);
		ObjSprite2D_SetSourceRect(obj,832,0,864,36);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		ObjRender_SetScaleXYZ(obj,0.6,0.6,0);
		Obj_SetRenderPriority(obj,1);
		ObjRender_SetPosition(obj,px,108,50);
	}
			task  RealLife(px,num){
			let obj=ObjPrim_Create(OBJ_SPRITE_2D);
			let img=GetCurrentScriptDirectory()~"img/front00.png";
			ObjPrim_SetTexture(obj,img);
			ObjSprite2D_SetSourceRect(obj,991,0,1022,36);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetBlendType(obj,BLEND_ALPHA);
			ObjRender_SetScaleXYZ(obj,0.6,0.6,0);
			Obj_SetRenderPriority(obj,1);
			ObjRender_SetPosition(obj,px-2,108,0);
			while(true){
			let point = GetPlayerLife();
			if(point>num){ObjRender_SetAlpha(obj,255);}
			else{ObjRender_SetAlpha(obj,0);}
			yield;
			}
	}
		task TText{
			let obj=ObjPrim_Create(OBJ_SPRITE_2D);
			let img=GetCurrentScriptDirectory()~"img/front01.png";
			ObjPrim_SetTexture(obj,img);
			ObjSprite2D_SetSourceRect(obj,256,36,304,54);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetBlendType(obj,BLEND_ALPHA);
			ObjRender_SetScaleXYZ(obj,1,1,0);
			Obj_SetRenderPriority(obj,1);
			ObjRender_SetPosition(obj,stgx+250,120,0);
			}
}

task TPlayerSpell
{
	//TText;
	ascent(i in 0..8){
	EmptyBomb(stgx+315+i*17);
	RealBomb(stgx+315+i*17,i);
	}
		task EmptyBomb(px){
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		let img=GetCurrentScriptDirectory()~"img/front00.png";
		let c = 255;
		ObjPrim_SetTexture(obj,img);
		ObjSprite2D_SetSourceRect(obj,832,36,864,75);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		ObjRender_SetScaleXYZ(obj,0.6,0.6,0);
		Obj_SetRenderPriority(obj,1);
		ObjRender_SetPosition(obj,px,136,0);
	}
			task  RealBomb(px,num){
			let obj=ObjPrim_Create(OBJ_SPRITE_2D);
			let img=GetCurrentScriptDirectory()~"img/front00.png";
			let c = 255;
			ObjPrim_SetTexture(obj,img);
			ObjSprite2D_SetSourceRect(obj,991,36,1022,75);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetBlendType(obj,BLEND_ALPHA);
			ObjRender_SetScaleXYZ(obj,0.6,0.6,0);
			Obj_SetRenderPriority(obj,1);
			ObjRender_SetPosition(obj,px-1,136,0);
			while(true){
			let point = GetPlayerSpell();
			if(point>num){ObjRender_SetAlpha(obj,255);}
			else{ObjRender_SetAlpha(obj,0);}
			yield;
			}
	}
		task TText{
			let obj=ObjPrim_Create(OBJ_SPRITE_2D);
			let img=GetCurrentScriptDirectory()~"img/front01.png";
			ObjPrim_SetTexture(obj,img);
			ObjSprite2D_SetSourceRect(obj,320,0,400,18);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetBlendType(obj,BLEND_ALPHA);
			ObjRender_SetScaleXYZ(obj,1,1,0);
			Obj_SetRenderPriority(obj,1);
			ObjRender_SetPosition(obj,stgx+258,143,0);
			}
}


//----------------------------------------------------
//ボスのライフ表示
//----------------------------------------------------
task TBossLife{
	let path = pathHealth;
	let countVertex = 100;
	let objScene = ID_INVALID;
	
	let objStar = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(objStar, GetCurrentScriptDirectory ~ "img/frame2.png");
	Obj_SetRenderPriority(objStar, 1);
	ObjSpriteList2D_SetSourceRect(objStar, 144, 80, 156, 92);
	ObjSpriteList2D_SetDestCenter(objStar);

	let objLife = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(objLife, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(objLife, countVertex);
	ObjRender_SetBlendType(objLife, BLEND_ALPHA);
	Obj_SetRenderPriority(objLife, 0.69);
	ObjPrim_SetTexture(objLife, path);

	let objOutline = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(objOutline, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(objOutline, countVertex);
	ObjRender_SetBlendType(objOutline, BLEND_ALPHA);
	Obj_SetRenderPriority(objOutline, 0.68);
	ObjPrim_SetTexture(objOutline, path);

	let objKnub = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(objKnub, path);
	Obj_SetRenderPriority(objKnub, 0.69);
	ObjSpriteList2D_SetSourceRect(objKnub, 20, 0, 29, 11);
	ObjSpriteList2D_SetDestRect(objKnub, -2.5, -3, 2.5, 3);

	ascent (iVert in 0..countVertex/2){
		let vertex = iVert * 2;
		ObjPrim_SetVertexUVT(objLife, vertex+0, 0, 0);
		ObjPrim_SetVertexUVT(objLife, vertex+1, 10, 32);
		ObjPrim_SetVertexUVT(objOutline, vertex+0, 10, 0);
		ObjPrim_SetVertexUVT(objOutline, vertex+1, 19, 32);
	}

	let mx = 0;
	let my = 0;
	let fade = 255;
	let fadec = 255;
	let maxRadius = 54;

	let lastRemStep = 0;
	let countRemStep = ObjEnemyBossScene_GetInfo(objScene, INFO_REMAIN_STEP_COUNT);
	let lifeRateRender = 0;
	let outlineRender = 0;

	let lifeTotalMax = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
	let lifeTotal = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_LIFE);
	let lifeRate = min(lifeTotal / lifeTotalMax, lifeRateRender);

	ObjRender_SetScaleXYZ(objLife, -1, 1, 1);
	ObjRender_SetScaleXYZ(objOutline, -1, 1, 1);
	
	ObjRender_SetPosition(objStar, 63-8*4, 30, 0);


	while(GetCommonData("quality", 2)==2){
		ObjSpriteList2D_ClearVertexCount(objStar);
		ObjSpriteList2D_ClearVertexCount(objKnub);

		objScene = GetEnemyBossSceneObjectID;
		if(objScene != ID_INVALID){
			let Boss = GetEnemyBossObjectID;
			Boss = Boss ~ [objLife];
			mx = ObjRender_GetX(Boss[0]);
			my = ObjRender_GetY(Boss[0]);
		}else{
			mx = -400;
			my = -400;
			outlineRender = 0;
			lifeRateRender = 0;
		}
		RefreshVertex(objLife);

		if(GetDistance(GetPlayerX,GetPlayerY,mx,my)<maxRadius*1.75){
			fadec = max(fadec-10, 85);
		}else{fadec = min(fadec+10, 255);}
		ObjRender_SetAlpha(objKnub, (fadec/100)*(lifeRateRender*100));
		ObjRender_SetAlpha(objOutline, fadec);
		ObjRender_SetAlpha(objLife, fadec);

		if(GetCommonData("ForceLifebar", 0) != 0){
			outlineRender = 0;
			lifeRateRender = 0;
		}


		lastRemStep = countRemStep;

		yield;
	}
	Obj_Delete(objStar);
	Obj_Delete(objKnub);
	Obj_Delete(objOutline);
	Obj_Delete(objLife);

	task RefreshVertex(objid){
		countRemStep = ObjEnemyBossScene_GetInfo(objScene, INFO_REMAIN_STEP_COUNT);
		if(lastRemStep != countRemStep){
			lifeRateRender = 0;
		}
		ascent(iStep in 0 .. countRemStep){
			ObjSpriteList2D_SetSourceRect(objStar, 144, 80, 156, 92);
			let y = truncate((iStep)/12)*12;
			let i = iStep-(12*(y/12));
			ObjSpriteList2D_SetDestRect(objStar, 4 + i * 12, 4+y,4 + (i + 1) * 12, 16+y);
			ObjSpriteList2D_AddVertex(objStar);
		}

		let listLifeDiv = [0]~ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_LIFE_RATE_LIST);
		ascent(iDiv in 0 .. length(listLifeDiv)){
			let kang = 360*(listLifeDiv[iDiv]);
			let kx = mx+(maxRadius*1.05)*cos(kang-90);
			let ky = my+(maxRadius*1.05)*sin(kang-90);
			if(1-listLifeDiv[iDiv]<lifeTotal / lifeTotalMax-0.000001){
				ObjRender_SetPosition(objKnub, kx, ky, 0);
				ObjRender_SetAngleZ(objKnub, kang);
				ObjSpriteList2D_AddVertex(objKnub);
			}
		}

		lifeTotalMax = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
		lifeTotal = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_LIFE);
		lifeRate = min(lifeTotal / lifeTotalMax, lifeRateRender);

		ascent(iVert in 0..countVertex/2){
			let indexVert = iVert * 2;
			let angle = (360 / (countVertex/2 - 1) * iVert);
			angle = min(360*(outlineRender), angle);
			let x = (maxRadius)*cos(angle-90);
			let y = (maxRadius)*sin(angle-90);
			ObjPrim_SetVertexPosition(objOutline, indexVert + 0 , x, y, 0);
			x = (maxRadius*1.1)*cos(angle-90);
			y = (maxRadius*1.1)*sin(angle-90);
			ObjPrim_SetVertexPosition(objOutline, indexVert + 1 , x, y, 0);

			angle = min(360*(lifeRate), angle);
			x = (maxRadius)*cos(angle-90);
			y = (maxRadius)*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife, indexVert + 0 , x, y, 0);
			x = (maxRadius*1.1)*cos(angle-90);
			y = (maxRadius*1.1)*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife, indexVert + 1 , x, y, 0);
		}
		ObjRender_SetPosition(objLife, mx,my, 0);
		ObjRender_SetPosition(objOutline, mx,my, 0);

		lifeRateRender = min(1, lifeRateRender+0.02);
		outlineRender = min(1, outlineRender+0.016);
		
	}
}


//----------------------------------------------------
//タイマー表示
//----------------------------------------------------
task TBossTimer
{
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetScaleXYZ( obj, 1.1, 1.1, 0 );
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 1);
	ObjRender_SetY(obj, 16);
	let count = 3;

	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, 999);
		let listNum = DigitToArray(timer, count);

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

}

//----------------------------------------------------
//スペルカード取得表示
//----------------------------------------------------
task TGainSpell(score)
{

	let Get = GCSD~"img/bonus.png";
	let objImg =ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objImg,Get);
	ObjSprite2D_SetSourceRect(objImg,0,0,276,44);
	ObjSprite2D_SetDestRect(objImg,-276,-44,276,44);
	ObjSprite2D_SetDestCenter(objImg);
	ObjRender_SetScaleXYZ(objImg,1.2,1.2,0);
	ObjRender_SetBlendType(objImg,BLEND_ALPHA);
	Obj_SetRenderPriority(objImg, 0.6);
	ObjRender_SetX(objImg, GetStgFrameWidth/2);
	ObjRender_SetY(objImg, 98);

	let strScore = "+" ~ IntToString(score);
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, strScore);
	ObjText_SetFontSize(objScore, 28);
	ObjText_SetFontBold(objScore, true);
		ObjText_SetFontColorTop(objScore,0,0,0);//255,255,255);
		ObjText_SetFontColorBottom(objScore,0,0,0);//255,255/2,255);
		ObjText_SetFontBorderType(objScore, BORDER_FULL);
		ObjText_SetFontBorderColor(objScore,255,255,255);//128,0,192);
		ObjText_SetFontBorderWidth(objScore, 2);
	Obj_SetRenderPriority(objScore, 0.6);
	ObjRender_SetX(objScore, 230);
	ObjRender_SetY(objScore, 144);

	loop(150)
	{
		yield;
	}
	Obj_Delete(objImg);
	Obj_Delete(objScore);
}

task TFailSpell
{

	let Get = GCSD~"img/bonusf.png";
	let objImg =ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objImg,Get);
	ObjSprite2D_SetSourceRect(objImg,0,0,276,44);
	ObjSprite2D_SetDestRect(objImg,-276,-44,276,44);
	ObjSprite2D_SetDestCenter(objImg);
	ObjRender_SetScaleXYZ(objImg,1.2,1.2,0);
	ObjRender_SetBlendType(objImg,BLEND_ALPHA);
	Obj_SetRenderPriority(objImg, 0.6);
	ObjRender_SetX(objImg, GetStgFrameWidth/2);
	ObjRender_SetY(objImg, 98);
	Move( objImg, 30 );
	fall( objImg, 30 );
	Fade( objImg, 50 );
}

	task Move( obj, t ){
	wait( t );
	let a = 0;
	let b = 0;
	while( !Obj_IsDeleted( obj )){
	ObjRender_SetY( obj, 98 + a );
	a+=b;
	b += 0.032;
	yield;
	}
	}

	task fall( obj, t ){
	wait( t );
	let a = 0;
	let b = 0;
	while( !Obj_IsDeleted( obj )){
	ObjRender_SetAngleZ( obj, a );
	a += b;
	b += 0.0052;
	yield;
	}
	}

	task Fade( obj, t ){
	wait( t );
	descent( i in 0..255/2.5 ){
	ObjRender_SetAlpha( obj, i*2.5 );
	yield;
	}
	Obj_Delete( obj );
	}

//----------------------------------------------------
//FPS表示
//----------------------------------------------------
task TCurrentFps()
{
	let objText = ObjText_Create();
	ObjText_SetFontSize(objText, 14);
	ObjText_SetFontBold(objText, true);
		ObjText_SetFontColorTop(objText,0,0,0);//255,255,255);
		ObjText_SetFontColorBottom(objText,0,0,0);//255,255/2,255);
		ObjText_SetFontBorderType(objText, BORDER_FULL);
		ObjText_SetFontBorderColor(objText,255,255,255);//128,0,192);
		ObjText_SetFontBorderWidth(objText, 2);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objText, GetScreenWidth() - 8);
	Obj_SetRenderPriority(objText, 2);
	ObjRender_SetX(objText, 0);
	ObjRender_SetY(objText, GetScreenHeight() - 22);

	loop
	{
		let fps = GetCurrentFps();
		let text = vtos("1.2f", fps) ~ "fps";
		ObjText_SetText(objText, text);
		yield;
	}
}

task TReplayFps()
{
	if(!IsReplay()){return;}

	let objText = ObjText_Create();
	ObjText_SetFontSize(objText, 12);
	ObjText_SetFontBold(objText, true);
		ObjText_SetFontColorTop(objText,0,0,0);//255,255,255);
		ObjText_SetFontColorBottom(objText,0,0,0);//255,255/2,255);
		ObjText_SetFontBorderType(objText, BORDER_FULL);
		ObjText_SetFontBorderColor(objText,255,255,255);//128,0,192);
		ObjText_SetFontBorderWidth(objText, 2);
	Obj_SetRenderPriority(objText, 1.0);

	let px = GetStgFrameLeft() + GetStgFrameWidth() - 18;
	let py = GetStgFrameTop() + GetScreenHeight() - 14;
	ObjRender_SetX(objText, px);
	ObjRender_SetY(objText, py);

	loop
	{
		let fps = GetReplayFps();
		let text = vtos("02d", fps);
		ObjText_SetText(objText, text);
		yield;
	}
}

//----------------------------------------------------
//ユーティリティ
//----------------------------------------------------
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;
}

task PlaySound(str,v,w){
	let s = ObjSound_Create;
	if(str == "select"){ObjSound_Load(s,GCSD~"sound/select.wav");}
	if(str == "ok"){ObjSound_Load(s,GCSD~"sound/ok.wav");}
	loop(w){yield;}
	ObjSound_SetSoundDivision(s,SOUND_SE);
	ObjSound_SetVolumeRate(s,v);
	ObjSound_Play(s);
}

function wait(t){
	loop(t){yield;}
	}
function GetDistance(x1,y1,x2,y2){
	return(((x2-x1)^2+(y2-y1)^2)^(1/2))
}