
let dirCurrent = GetCurrentScriptDirectory();
let GCSD = GetCurrentScriptDirectory();

let pathSystem = GCSD ~ "./img/System.png";


@Initialize
{
	TCurrentFps();
	TReplayFps();
	InitFrame();
	TScore();
	TGraze();
	TPlayerLife();
	TPlayerSpell();
	TBossLife();
	TBossTimer();
	AddLives;
	Invincibility;
	
	SetPauseScriptPath(GCSD ~ "Default_Pause.txt");
	SetEndSceneScriptPath(GCSD ~ "Default_EndScene.txt");
	SetReplaySaveSceneScriptPath(GCSD ~ "Default_ReplaySaveScene.txt");
	LoadItemData(GetCurrentScriptDirectory ~ "./item/Itemdata.txt");
	StartItemScript(GetCurrentScriptDirectory ~ "./item/Itemscript.txt");
	let sc = LoadScript(GCSD ~ "Default_Sounds.txt");
	StartScript(sc);
	let sc2 = LoadScript(GCSD ~ "Default_Textures.txt");
	StartScript(sc2);
}

@MainLoop
{
	yield;
}

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

//----------------------------------------------------
//枠外の背景表示
//----------------------------------------------------
function InitFrame()
{
	let path = GetCurrentScriptDirectory() ~ "img/aaaaaa.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0.8);
	ObjSprite2D_SetSourceRect(obj, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
	ObjSprite2D_SetDestRect(obj, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
	
	let path2 = GetCurrentScriptDirectory() ~ "img/bbbbbbb.png";
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj2, path2);
	Obj_SetRenderPriority(obj2, 0.8);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
	ObjSprite2D_SetDestRect(obj2, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
	SetStgFrame(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 20, 80);
}

//----------------------------------------------------
//スコア表示
//----------------------------------------------------
task TScore()
{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, pathSystem);
	Obj_SetRenderPriority(obj, 0.9);
	ObjSprite2D_SetSourceRect(obj, 380, 538,  380+90, 538+38);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, 0.6, 0.6, 0);
	ObjRender_SetX(obj, 30+30);
	ObjRender_SetY(obj, 90-8+20);
	
	let objBar = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objBar, pathSystem);
	Obj_SetRenderPriority(objBar, 0.9);
	ObjSprite2D_SetSourceRect(objBar, 0, 0, 256, 8);
	ObjSprite2D_SetDestCenter(objBar);
	ObjRender_SetScaleXYZ(objBar, 0.45, 0.75, 0);
	ObjRender_SetBlendType(objBar, BLEND_ADD_ARGB);
	ObjRender_SetX(objBar, 30+35);
	ObjRender_SetY(objBar, 90+25+20);
	
	let objScore = ObjText_Create();
	ObjText_SetFontType(objScore, "Modern No. 20");
	ObjText_SetFontSize(objScore, 20);
	ObjText_SetFontBold(objScore, false);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 255, 255);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,0, 0, 0);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.9);
	ObjRender_SetX(objScore, 30+90-150);
	ObjRender_SetY(objScore, 90+20);
	ObjText_SetHorizontalAlignment(objScore, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objScore, 150);
	
	let objH = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objH, pathSystem);
	Obj_SetRenderPriority(objH, 0.9);
	ObjSprite2D_SetSourceRect(objH, 380, 499,  380+122, 499+36);
	ObjSprite2D_SetDestCenter(objH);
	ObjRender_SetScaleXYZ(objH, 0.6, 0.6, 0);
	ObjRender_SetX(objH, 30+30);
	ObjRender_SetY(objH, 90-8-45);
	
	let objHBar = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objHBar, pathSystem);
	Obj_SetRenderPriority(objHBar, 0.9);
	ObjSprite2D_SetSourceRect(objHBar, 0, 0, 256, 8);
	ObjSprite2D_SetDestCenter(objHBar);
	ObjRender_SetScaleXYZ(objHBar, 0.45, 0.75, 0);
	ObjRender_SetBlendType(objHBar, BLEND_ADD_ARGB);
	ObjRender_SetX(objHBar, 30+35);
	ObjRender_SetY(objHBar, 90+25+20-60);
	
	let objHScore = ObjText_Create();
	ObjText_SetFontType(objHScore, "Modern No. 20");
	ObjText_SetFontSize(objHScore, 20);
	ObjText_SetFontBold(objHScore, false);
	ObjText_SetFontColorTop(objHScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objHScore, 255, 255, 255);
	ObjText_SetFontBorderType(objHScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objHScore,0, 0, 0);
	ObjText_SetFontBorderWidth(objHScore, 1);
	Obj_SetRenderPriority(objHScore, 0.9);
	ObjRender_SetX(objHScore, 30+90-150);
	ObjRender_SetY(objHScore, 90+20-60);
	ObjText_SetHorizontalAlignment(objHScore, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objHScore, 150);
	
	CreateCommonDataArea("HighScore");
	let high = LoadCommonDataAreaA2("HighScore",GetCurrentScriptDirectory ~ "./score.dat");
	
	if(!high){SetAreaCommonData("HighScore","Score",0); }

	
	while(true)
	{
		let score = GetScore();
		let scoreint = IntToString(score);
		
		let scoreH = vtos("010d", GetAreaCommonData("HighScore","Score",0));
		let scoreE = vtos("010d", scoreint);
		
		if(GetScore() > GetAreaCommonData("HighScore","Score",0))  {SetAreaCommonData("HighScore","Score",GetScore()); SetCommonData("GotHighScore", 1);}
		ObjText_SetText(objScore, scoreE);
		ObjText_SetText(objHScore, scoreH);
		yield;
	}
}

//----------------------------------------------------
//Graze表示
//----------------------------------------------------

task TGraze()
{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, pathSystem);
	Obj_SetRenderPriority(obj, 0.9);
	ObjSprite2D_SetSourceRect(obj, 380, 451,  380+96, 451+39);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, 0.6, 0.6, 0);
	ObjRender_SetX(obj, 428+70+75);
	ObjRender_SetY(obj, 175-40);
	
	let objBar = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objBar, pathSystem);
	Obj_SetRenderPriority(objBar, 0.9);
	ObjSprite2D_SetSourceRect(objBar, 0, 0, 256, 8);
	ObjSprite2D_SetDestCenter(objBar);
	ObjRender_SetScaleXYZ(objBar, 0.45, 0.75, 0);
	ObjRender_SetBlendType(objBar, BLEND_ADD_ARGB);
	ObjRender_SetColor(objBar, 155, 155, 155);
	ObjRender_SetX(objBar, 428+100+45);
	ObjRender_SetY(objBar, 175-8);
	
	let objScore = ObjText_Create();
	ObjText_SetFontType(objScore, "Modern No. 20");
	ObjText_SetFontSize(objScore, 20);
	ObjText_SetFontBold(objScore, false);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 255, 255);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,0, 0, 0);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.9);
	ObjRender_SetX(objScore, 428+175-150);
	ObjRender_SetY(objScore, 175-32);
	ObjText_SetHorizontalAlignment(objScore, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objScore, 150);
	
	while(true)
	{
		let graze = GetGraze();
		let grazeint = vtos("05d", graze);
		
		ObjText_SetText(objScore, grazeint);
		yield;
	}
}

//----------------------------------------------------
//残機表示
//----------------------------------------------------
task TPlayerLife
{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, pathSystem);
	Obj_SetRenderPriority(obj, 0.9);
	ObjSprite2D_SetSourceRect(obj, 381, 360,  381+76, 360+38);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, 0.6, 0.6, 0);
	ObjRender_SetX(obj, 528+15);
	ObjRender_SetY(obj, 218-20);
	
	let objBar = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objBar, pathSystem);
	Obj_SetRenderPriority(objBar, 0.9);
	ObjSprite2D_SetSourceRect(objBar, 0, 0, 256, 8);
	ObjSprite2D_SetDestCenter(objBar);
	ObjRender_SetScaleXYZ(objBar, 0.25, 0.75, 0);
	ObjRender_SetBlendType(objBar, BLEND_ADD_ARGB);
	ObjRender_SetColor(objBar, 255, 0, 225);
	ObjRender_SetX(objBar, 528+15);
	ObjRender_SetY(objBar, 218-8);
	
	ascent(i in 1..10){
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,pathSystem);
		ObjSprite2D_SetSourceRect(obj,166,197,166+144,197+155);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetScaleXYZ(obj, 0.15, 0.15, 0);
		Obj_SetRenderPriority(obj, 0.9);
		ObjRender_SetPosition(obj, 544, 200+i*25, 0);
	}

	while(true)
	{
		let lives = GetPlayerLife;
		RenderLives;
			while(true){
			if(lives!=GetPlayerLife()){break;}
			yield;
			}
	}
	
	task RenderLives{    
		ascent(i in 1..GetPlayerLife+1){
			let obj = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjPrim_SetTexture(obj,pathSystem);
			ObjSprite2D_SetSourceRect(obj,0,198,144,198+155);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetScaleXYZ(obj, 0.15, 0.15, 0);
			Obj_SetRenderPriority(obj, 0.9);
			ObjRender_SetPosition(obj, 544, 200+i*25, 0);
			trigger(obj, GetPlayerLife, i);
		}
	}
	task trigger(obj, lives,i){
	if(i>9){Obj_Delete(obj);}
		while(!Obj_IsDeleted(obj)){
		if(lives!=GetPlayerLife()){
		Obj_Delete(obj);
		break;
		}
		yield;
		}
	}
}

//----------------------------------------------------
//残スペル表示
//----------------------------------------------------
task TPlayerSpell
{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, pathSystem);
	Obj_SetRenderPriority(obj, 0.9);
	ObjSprite2D_SetSourceRect(obj, 381, 404,  381+114, 404+38);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, 0.6, 0.6, 0);
	ObjRender_SetX(obj, 528+15+65);
	ObjRender_SetY(obj, 218-20);
	
	let objBar = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objBar, pathSystem);
	Obj_SetRenderPriority(objBar, 0.9);
	ObjSprite2D_SetSourceRect(objBar, 0, 0, 256, 8);
	ObjSprite2D_SetDestCenter(objBar);
	ObjRender_SetScaleXYZ(objBar, 0.25, 0.75, 0);
	ObjRender_SetBlendType(objBar, BLEND_ADD_ARGB);
	ObjRender_SetColor(objBar, 0, 255, 15);
	ObjRender_SetX(objBar, 528+15+65);
	ObjRender_SetY(objBar, 218-8);
	
	ascent(i in 1..10){
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,pathSystem);
		ObjSprite2D_SetSourceRect(obj,171,11,171+144,11+155);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetScaleXYZ(obj, 0.15, 0.15, 0);
		Obj_SetRenderPriority(obj, 0.9);
		ObjRender_SetPosition(obj, 540+65, 200+i*25, 0);
	}

	while(true)
	{
		let bombs = GetPlayerSpell;
		RenderBombs;
			while(true){
			if(bombs!=GetPlayerSpell()){break;}
			yield;
			}
	}
	
	task RenderBombs{    
		ascent(i in 1..GetPlayerSpell+1){
			let obj = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjPrim_SetTexture(obj,pathSystem);
			ObjSprite2D_SetSourceRect(obj,12,11,12+144,11+155);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetScaleXYZ(obj, 0.15, 0.15, 0);
			Obj_SetRenderPriority(obj, 0.9);
			ObjRender_SetPosition(obj, 540+65, 200+i*25, 0);
			trigger(obj, GetPlayerSpell, i);
		}
	}
	task trigger(obj, bombs,i){
	if(i>6){Obj_Delete(obj);}
		while(!Obj_IsDeleted(obj)){
		if(bombs!=GetPlayerSpell()){
		Obj_Delete(obj);
		break;
		}
		yield;
		}
	}
}

//----------------------------------------------------
//ボスのライフ表示
//----------------------------------------------------
task TBossLife
{

	//let objScene = GetEnemyBossSceneObjectID();
	//let objBoss = GetEnemyBossObjectID()[0];
	
	let path = GetCurrentScriptDirectory() ~ "img/Default_System.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0.91);
	
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj2, pathSystem);
	Obj_SetRenderPriority(obj2, 0.9);
	ObjSprite2D_SetSourceRect(obj2, 68, 635, 68+270, 635+27);
	ObjSprite2D_SetDestCenter(obj2);
	ObjRender_SetAngleZ(obj2, 90);
	ObjRender_SetScaleXYZ(obj2, 1, 1, 1);
	ObjRender_SetPosition(obj2, 80, 305, 0);
	
	let objStar = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(objStar, pathSystem);
	Obj_SetRenderPriority(objStar, 0.91);
	//ObjRender_SetScaleXYZ(objStar, 1.5, 1, 1);
	ObjSpriteList2D_SetSourceRect(objStar, 252, 518, 252+94, 518+97);

	let lastRemStep = -1;
	let lifeRateRender = 0;

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


	function RenderLife()
	{
		//残りステップ
		let countRemStep = ObjEnemyBossScene_GetInfo(objScene, INFO_REMAIN_STEP_COUNT);
		if(lastRemStep != countRemStep)
		{
			//ステップが変化
			lifeRateRender = 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);
		ObjSpriteList2D_SetSourceRect(obj, 1, 1, 127, 11);
		ObjSpriteList2D_SetDestRect(obj, 64+7, 436, 78+12, 436 - 262 * lifeRate);
		ObjSpriteList2D_AddVertex(obj);

		//ライフの区切り表示
		ObjSpriteList2D_SetSourceRect(obj, 132, 1, 137, 11);
		let listLifeDiv = [0] ~ ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_LIFE_RATE_LIST);
		ascent(iDiv in 0 .. length(listLifeDiv))
		{
			let rate = listLifeDiv[iDiv];
			let y = 436 - 262 * (1-rate);
			ObjSpriteList2D_SetDestRect(obj, 64+7, y-1, 78+5, y+1);
			ObjSpriteList2D_AddVertex(obj);
		}

		//残りステップ表示
		ObjSpriteList2D_SetSourceRect(obj, 1, 1, 127, 11);
		ObjSpriteList2D_ClearVertexCount(objStar);
		ascent(iStep in 0 .. countRemStep)
		{
			let y = truncate((iStep)/12)*12;
			let i = iStep-(12*(y/12));
			ObjSpriteList2D_SetDestRect(objStar, 36+4, 4+410 - i * 31,
				36+32, 32+410 - i * 31 );
			ObjSpriteList2D_AddVertex(objStar);
		}

		lifeRateRender += 0.01;
		lifeRateRender = min(lifeRateRender, 1);
		lastRemStep = countRemStep;
	}
}

//----------------------------------------------------
//タイマー表示
//----------------------------------------------------
task TBossTimer
{
	InstallFont(GetCurrentScriptDirectory() ~ "DD.ttf");
	let objText = ObjText_Create();
	ObjText_SetFontSize(objText, 22);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontType(objText, "Sitka");
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText, 25, 25, 255);
	ObjText_SetFontBorderWidth(objText, 1.5);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objText, GetStgFrameWidth-24);
	Obj_SetRenderPriority(objText, 1.0);
	
	ObjRender_SetX(objText, -270);
	ObjRender_SetY(objText, 12);
	
	let objScene = ID_INVALID;
	loop
	{
		objScene = GetEnemyBossSceneObjectID();
		if(objScene != ID_INVALID)
		{
			RenderTimer();
		}
		yield;
	}

	function RenderTimer()
	{
	let timer = rtos("000.00", ObjEnemyBossScene_GetInfo(objScene, INFO_TIMERF) / 60);
	ObjText_SetText(objText, timer);
		if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER) < 11){
		ObjText_SetFontBorderColor(objText, 255, 25, 25);
		}
		if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER) > 11){
		ObjText_SetFontBorderColor(objText, 25, 25, 255);
		}
	if(GetCommonData("RenderTimer", 1) == 1){Obj_SetVisible(objText, 1);}
	if(GetCommonData("RenderTimer", 1) == 0){Obj_SetVisible(objText, 0);}
	}
}

//----------------------------------------------------
//スペルカード取得表示
//----------------------------------------------------
task TGainSpell(score)
{
	let text = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriority(text, 0.7);
	ObjPrim_SetTexture(text,pathSystem);
	ObjSprite2D_SetSourceRect(text,374,4,374+346,4+45);
	ObjSprite2D_SetDestCenter(text);
	ObjRender_SetPosition(text, GetStgFrameWidth/2, 125, 0);
	ObjRender_SetAlpha(text, 255);
	ObjRender_SetScaleXYZ(text, 1, 1, 1);

	let strScore = "+" ~ IntToString(score);
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, strScore);
	ObjText_SetFontType(objScore, "Modern No. 20");
	ObjText_SetFontSize(objScore, 38);
	ObjText_SetFontBold(objScore, false);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 255, 255);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,0, 0, 0);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.6);
	ObjRender_SetX(objScore, GetStgFrameHeight/2);
	ObjRender_SetY(objScore, 150);


	loop(120)
	{
		yield;
	}
	ascent(i in 0..60){
	ObjRender_SetAlpha(text, 255-i*10);
	ObjRender_SetAlpha(objScore, 255-i*10);
	yield;
	}
	Obj_Delete(text);
	Obj_Delete(objScore);
}

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

	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, 128, 128, 255);
	ObjText_SetFontColorBottom(objText, 64, 64, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,255, 255, 255);
	ObjText_SetFontBorderWidth(objText, 1);
	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 Invincibility{
	AddVirtualKey(VK_USER1,KEY_SPACE,KEY_INVALID);
	
	loop{
		if(GetVirtualKeyState(VK_USER1)==KEY_HOLD){
		SetPlayerInvincibilityFrame(30);}
	yield;}	
}

task AddLives{
	AddVirtualKey(VK_USER2,KEY_L,KEY_INVALID);
	
	loop{
		if(GetVirtualKeyState(VK_USER2)==KEY_PUSH){
		SetPlayerLife(GetPlayerLife+1);}
	yield;}	
}

