#include"./PackageFunctions.txt"
let dirCurrent = GetCurrentScriptDirectory();
let diff;
let diff1 = GetAreaCommonData("Day","Day",1);
@Initialize
{
	InitFrame();
	TScore();
	//THiScore;
	TGraze();
	TPlayerLife();
	TPlayerSpell();
	StartItemScript(GetCurrentScriptDirectory()~"Item.txt");
	InstallFont(GetCurrentScriptDirectory()~"Cirno.ttf");
	TBossLife();
	TBossTimer();
	TCurrentFps();
	TReplayFps();
	TSpellCheck();
	StartScript(dirCurrent~"Default_System_MagicCircle.txt");
	LoadAllSound;
	LoadAllMusic;
	TDifficultyWrite();
}
	@Loading{
		LoadTexture(GetFileDirectory(GetMainPackageScriptPath())~"script/Day1/img/14.-water-texture.png");
		LoadTexture(GetFileDirectory(GetMainPackageScriptPath())~"script/Day1/img/4706.jpg");
		LoadTexture(GetFileDirectory(GetMainPackageScriptPath())~"script/Day1/img/bg1.png");
		LoadTexture(GetFileDirectory(GetMainPackageScriptPath())~"script/Day1/img/bg2.png");
		LoadTexture(GetFileDirectory(GetMainPackageScriptPath())~"script/Day1/img/black.png");
		LoadTexture(GetFileDirectory(GetMainPackageScriptPath())~"script/Day1/img/enemy.png");
		LoadTexture(GetFileDirectory(GetMainPackageScriptPath())~"script/Day1/img/generic.png");
		LoadTexture(GetFileDirectory(GetMainPackageScriptPath())~"script/Day1/img/serenity.png");
		LoadTexture(GetFileDirectory(GetMainPackageScriptPath())~"script/Day1/img/specterb.png");
		LoadTexture(GetFileDirectory(GetMainPackageScriptPath())~"script/Day1/img/stg3enm.png");
		LoadTexture(GetCurrentScriptDirectory()~"img/charge.png");
		LoadTexture(GetCurrentScriptDirectory()~"img/circle.png");
		LoadTexture(GetCurrentScriptDirectory()~"img/Default_System.png");
		LoadTexture(GetCurrentScriptDirectory()~"img/Default_SystemBackground.png");
		LoadTexture(GetCurrentScriptDirectory()~"img/eff01.png");
		LoadTexture(GetCurrentScriptDirectory()~"img/effect.png");
		LoadTexture(GetCurrentScriptDirectory()~"img/Items.png");
		LoadTexture(GetCurrentScriptDirectory()~"img/timeitem.png");
		LoadTexture(GetCurrentScriptDirectory()~"img/tree.png");
	}
@MainLoop
{
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_START_BOSS_SPELL)
	{


	}
	case(EV_GAIN_SPELL)
	{
		let objScene = GetEnemyBossSceneObjectID();
		let score = ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE);
		TGainSpell(score);
	}
}

//----------------------------------------------------
//
//----------------------------------------------------
function InitFrame()
{
	let path = GetCurrentScriptDirectory() ~ "img/Default_SystemBackground.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 TDifficultyWrite{
	yield;
	let objTxt = ObjText_Create();
	Obj_SetRenderPriority(objTxt, 0.1);
	ObjText_SetHorizontalAlignment(objTxt,ALIGNMENT_CENTER);
	ObjText_SetMaxWidth(objTxt, 300);
	ObjText_SetFontSize(objTxt,25);
	ObjText_SetFontBorderType(objTxt,BORDER_FULL);
	ObjText_SetFontBorderWidth(objTxt,2);
	ObjRender_SetPosition(objTxt,640-224/2-150,20,0);
	ObjText_SetFontType(objTxt, "Cirno");
	diff = GetCommonData("Difficulty",0 );
	if(GetCommonData("Difficulty", 0)==0){
		ObjText_SetText(objTxt,"EASY");
		ObjText_SetFontColorTop(objTxt,120,255,120);
		ObjText_SetFontColorBottom(objTxt,255,255,255);
		ObjText_SetFontBorderColor(objTxt,0,255,0);
	}
	if(GetCommonData("Difficulty", 0)==1){
		ObjText_SetText(objTxt,"NORMAL");
		ObjText_SetFontColorTop(objTxt,120,120,255);
		ObjText_SetFontColorBottom(objTxt,255,255,255);
		ObjText_SetFontBorderColor(objTxt,0,0,255);
	}
	if(GetCommonData("Difficulty", 0)==2){
		ObjText_SetText(objTxt,"HARD");
		ObjText_SetFontColorTop(objTxt,255,120,120);
		ObjText_SetFontColorBottom(objTxt,255,255,255);
		ObjText_SetFontBorderColor(objTxt,255,0,0);
	}
	if(GetCommonData("Difficulty", 0)==3){
		ObjText_SetText(objTxt,"LUNATIC");
		ObjText_SetFontColorTop(objTxt,255,120,255);
		ObjText_SetFontColorBottom(objTxt,255,255,255);
		ObjText_SetFontBorderColor(objTxt,255,0,255);
	}
}

task TSpellCheck()
{
	loop{
		if(GetCommonData("scorecheck",0)==1){
			TGainSpell(GetCommonData("Score",0));
			SetCommonData("scorecheck",0);
		} else if(GetCommonData("scorecheck",0)==2){
			TFailSpell();
			SetCommonData("scorecheck",0);
		}
		yield;
	}
}
task TScore()
{
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, "Score");
	ObjText_SetFontType(objScore, "Cirno");
	ObjText_SetFontSize(objScore, 20);
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 255, 128, 128);
	ObjText_SetFontColorBottom(objScore, 255, 0, 128);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,0, 0, 0);
	ObjText_SetFontBorderWidth(objScore, 2);
	Obj_SetRenderPriority(objScore, 0.01);
	ObjRender_SetX(objScore, 425);
	ObjRender_SetY(objScore, 61);

	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_ALPHA);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 64);


	while(true)
	{
		let graze = GetScore();
		graze = min(graze, 999999999);
		let listNum = DigitToArray(graze, count);
		count = GetNumSize(graze);
		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, (600- (count-iObj-1) * 14));
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 0, (num + 1) * 16, 20);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 20);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}

/*task THiScore()
{
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, "HiScore");
	ObjText_SetFontType(objScore, "Snow White");
	ObjText_SetFontSize(objScore, 32);
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 128, 128, 255);
	ObjText_SetFontColorBottom(objText, 255, 0, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,0, 0, 0);
	ObjText_SetFontBorderWidth(objText, 2);
	Obj_SetRenderPriority(objText, 0.01);
	ObjRender_SetX(objText, 560);
	ObjRender_SetY(objText, 116);

	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_ALPHA);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 72);

		let objScoreType = ObjText_Create();
		ObjText_SetText(objScoreType, IntToString(GetScore));
		ObjText_SetFontType(objScoreType, "Snow White");
		ObjText_SetFontSize(objScoreType, 30);
		ObjText_SetFontBold(objScoreType, true);
		ObjText_SetFontColorTop(objScoreType, 128, 128, 128);
		ObjText_SetFontColorBottom(objScoreType, 196, 196, 196);
		ObjText_SetFontBorderType(objScoreType, BORDER_FULL);
		ObjText_SetHorizontalAlignment(objScoreType, ALIGNMENT_LEFT);
		ObjText_SetMaxWidth(objScoreType, 300);
		ObjText_SetFontBorderColor(objScoreType,0, 0, 0);
		ObjText_SetFontBorderWidth(objScoreType, 1);
		Obj_SetRenderPriority(objScoreType, 0.01);
		ObjRender_SetX(objScoreType, 10);
		ObjRender_SetY(objScoreType, 50);
	while(true)
	{
		ObjText_SetText(objScoreType, IntToString(max(GetScore,GetAreaCommonData("SpellData","HiScore" ~ IntToString(diff1),0 ))));
		yield;
	}
}*/

//----------------------------------------------------
//Graze
//----------------------------------------------------
task TGraze()
{
	let objGraze = ObjText_Create();
	ObjText_SetText(objGraze, "Graze");
	ObjText_SetFontType(objGraze, "Cirno");
	ObjText_SetFontSize(objGraze, 20);
	ObjText_SetFontBold(objGraze, true);
	ObjText_SetFontColorTop(objGraze, 200, 200, 200);
	ObjText_SetFontColorBottom(objGraze, 100, 100, 100);
	ObjText_SetFontBorderType(objGraze, BORDER_FULL);
	ObjText_SetFontBorderColor(objGraze, 0, 0, 0);
	ObjText_SetFontBorderWidth(objGraze, 2);
	Obj_SetRenderPriority(objGraze, 0.01);
	ObjRender_SetX(objGraze, 425);
	ObjRender_SetY(objGraze, 223);

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

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 226);

	while(true)
	{
		let graze = GetGraze();
		graze = min(graze, 999999);
		let listNum = DigitToArray(graze, count);
		count = GetNumSize(graze);
		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, (600- (count-iObj-1) * 14));
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 0, (num + 1) * 16, 20);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 20);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}
task TPIV()
{
	//Graze
	let objGraze = ObjText_Create();
	ObjText_SetText(objGraze, "PIV");
	ObjText_SetFontType(objGraze, "Cirno");
	ObjText_SetFontSize(objGraze, 20);
	ObjText_SetFontBold(objGraze, true);
	ObjText_SetFontColorTop(objGraze, 100, 100, 255);
	ObjText_SetFontColorBottom(objGraze, 100, 100, 255);
	ObjText_SetFontBorderType(objGraze, BORDER_FULL);
	ObjText_SetFontBorderColor(objGraze,0, 0, 0);
	ObjText_SetFontBorderWidth(objGraze, 2);
	Obj_SetRenderPriority(objGraze, 0.01);
	ObjRender_SetX(objGraze, 440);
	ObjRender_SetY(objGraze, 206);

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

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 206);

	while(true)
	{
		let piv = 100000 + GetGraze()*10 + GetCommonData("PIVITEM",0);
		piv = min(piv, 999990);
		let listNum = DigitToArray(piv, count);
		count = GetNumSize(piv);
		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 520 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 0, (num + 1) * 16, 20);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 20);
			ObjSpriteList2D_AddVertex(obj);
		}
		SetCommonData("PIValue",piv);
		yield;
	}
}

//----------------------------------------------------
//
//----------------------------------------------------
task TPlayerLife
{
	let x = 1;
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Player");
	ObjText_SetFontType(objText, "Cirno");
	ObjText_SetFontSize(objText, 20);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 150, 255);
	ObjText_SetFontColorBottom(objText, 255, 100, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,0, 0, 0);
	ObjText_SetFontBorderWidth(objText, 2);
	Obj_SetRenderPriority(objText, 0.01);
	ObjRender_SetX(objText, 425);
	ObjRender_SetY(objText, 95);

	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_Lives.png";
	let count = 2;
	while(x<9){
		liveholder(x);
		x++;
	}
	x = 1;
	loop{
		if(GetPlayerLife>8){SetPlayerLife(8);}
		while(x<GetPlayerLife+1){
			live(x);
			x++;
		}
		while(x>GetPlayerLife+1){
			x = GetPlayerLife+1;
		}
		yield;
	}
	task liveholder(life){
		let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(obj, pathDigit);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.11);
		ObjRender_SetY(obj, 100);
		let point = life;

		while(true)
		{
			point = min(point, 8);
			point = max(point, 0);
			let listNum = DigitToArray(point, count);

			ObjSpriteList2D_ClearVertexCount(obj);
			ObjRender_SetX(obj, 600 - 14*9 + (life-1)*18 );
			ObjSpriteList2D_SetSourceRect(obj, 16, 0, 32, 16);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj);
			yield;
		}
	}
	task live(life){
		let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(obj, pathDigit);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.12);
		ObjRender_SetY(obj, 100);
		let point = life;

		while(true)
		{
			point = min(point, 8);
			point = max(point, 0);
			let listNum = DigitToArray(point, count);

			ObjSpriteList2D_ClearVertexCount(obj);
			ObjRender_SetX(obj, 600 - 14*9 + (life-1)*18 );
			ObjSpriteList2D_SetSourceRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj);
			if(GetPlayerLife<point){
				Obj_Delete(obj);
			}
			yield;
		}
	}
}

//----------------------------------------------------
//----------------------------------------------------
task TPlayerSpell
{
	let objText = ObjText_Create();
	let x = 1;
	ObjText_SetText(objText, "Spell");
	ObjText_SetFontType(objText, "Cirno");
	ObjText_SetFontSize(objText, 20);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 150, 255, 150);
	ObjText_SetFontColorBottom(objText, 100, 255, 100);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,0, 0, 0);
	ObjText_SetFontBorderWidth(objText, 2);
	Obj_SetRenderPriority(objText, 0.01);
	ObjRender_SetX(objText, 425);
	ObjRender_SetY(objText, 127);

	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_Lives.png";
	let count = 2;
	while(x<9){
		bombholder(x);
		x++;
	}
	x = 1;
	loop{
	while(x<GetPlayerSpell+1){
		bomb(x);
		x++;
	}
	while(x>GetPlayerSpell+1){
		x = GetPlayerSpell+1;
	}
	yield;
}
	task bombholder(spell){
		let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(obj, pathDigit);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.11);
		ObjRender_SetY(obj, 130);
		let point = spell;

		while(true)
		{
			point = min(point, 8);
			point = max(point, 0);
			let listNum = DigitToArray(point, count);

			ObjSpriteList2D_ClearVertexCount(obj);
			ObjRender_SetX(obj, 600 - 14*9 + (spell-1)*18 );
			ObjSpriteList2D_SetSourceRect(obj, 16, 16, 32, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj);
			yield;
		}
	}
	task bomb(spell){
		let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(obj, pathDigit);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.12);
		ObjRender_SetY(obj, 130);
		let point = spell;

		while(true)
		{
			point = min(point, 8);
			point = max(point, 0);
			let listNum = DigitToArray(point, count);

			ObjSpriteList2D_ClearVertexCount(obj);
			ObjRender_SetX(obj, 600 - 14*9 + (spell-1)*18 );
			ObjSpriteList2D_SetSourceRect(obj, 0, 16, 16, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj);
			if(GetPlayerSpell<point){
				Obj_Delete(obj);
			}
			yield;
		}
	}
}

//----------------------------------------------------
//
//----------------------------------------------------
task TBossLife
{
	let path = GetCurrentScriptDirectory() ~ "img/Default_System.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0.7);

	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, 72, 8, 72 + 300 * lifeRate, 12);
		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 x = 72 + 300 * (1-rate);
			ObjSpriteList2D_SetDestRect(obj, x-1, 4, x + 1, 14);
			ObjSpriteList2D_AddVertex(obj);
		}

		//残りステップ表示
		ObjSpriteList2D_SetSourceRect(obj, 1, 1, 127, 11);
		ascent(iStep in 0 .. countRemStep)
		{
			let remStepRate = 58 / countRemStep;
			ObjSpriteList2D_SetDestRect(obj, 4 + iStep * remStepRate + 2, 8,
				4 + (iStep + 1) * remStepRate, 12);
			ObjSpriteList2D_AddVertex(obj);
		}

		lifeRateRender += 0.01;
		lifeRateRender = min(lifeRateRender, 1);
		lastRemStep = countRemStep;
	}
}
//----------------------------------------------------
//----------------------------------------------------
task TBossTimer
{
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";
	let frame = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.75);
	ObjRender_SetY(obj, 30);
	let count = 2;

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

	function RenderTimer()
	{
		let timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER);
		timer = min(timer, 99);
		let listNum = DigitToArray(timer, count);
		if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER)<=10){
			if(frame%60==0){
				DelaySE("STimeout1",0,20,0);
			}
			ObjRender_SetColor(obj, 155,0,0);
		} else {
			ObjRender_SetColor(obj, 255,255,255);
		}		
		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, GetStgFrameWidth/2-7 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 0, (num + 1) * 16, 20);
			ObjSpriteList2D_SetDestRect(obj, -8, -10, 8, 10);
			ObjSpriteList2D_AddVertex(obj);
		}
	}

}

//----------------------------------------------------
//----------------------------------------------------
task TGainSpell(score)
{
	TPointGain(score);
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Spell Capture!");
	ObjText_SetFontType(objText, "Cirno");
	ObjText_SetFontSize(objText, 32);
	ObjText_SetFontBold(objText, false);
	ObjText_SetFontColorTop(objText, 156, 196, 255);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_CENTER);
	ObjText_SetMaxWidth(objText, 300);
	ObjText_SetFontColorBottom(objText, 128, 156, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText, 0, 0, 0);
	ObjText_SetFontBorderWidth(objText, 1);
	ObjText_SetAutoTransCenter(objText, true );
	Obj_SetRenderPriority(objText, 0.3);	
	ObjRender_SetX(objText, GetStgFrameHeight()/2-150-40);
	ObjRender_SetY(objText, 140);

	let strScore = "Bonus: " ~ IntToString(score);
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, strScore);
	ObjText_SetFontType(objScore, "Cirno");
	ObjText_SetFontSize(objScore, 24);
	ObjText_SetFontBold(objScore, false);
	ObjText_SetFontColorTop(objScore, 156, 196, 255);
	ObjText_SetHorizontalAlignment(objScore, ALIGNMENT_CENTER);
	ObjText_SetFontColorBottom(objScore, 128, 156, 255);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore, 0, 0, 0);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.3);
	ObjText_SetAutoTransCenter(objScore, true );
	ObjText_SetMaxWidth(objScore, 300);
	ObjRender_SetX(objScore, GetStgFrameHeight()/2-150-40);
	ObjRender_SetY(objScore, 180);
	//DelaySE("SSpell2",0,10,0);
	loop(120)
	{
		yield;
	}
	Obj_Delete(objText);
	Obj_Delete(objScore);
}
task TPointGain(SScore)
{
	loop(60){
		AddScore(SScore/60);
		yield;
	}
}
task TFailSpell()
{
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Bonus Failed");
	ObjText_SetFontSize(objText, 26);
	ObjText_SetFontBold(objText, false);
	ObjText_SetFontColorTop(objText, 255, 196,196);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_CENTER);
	ObjText_SetFontColorBottom(objText, 255, 64, 64);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,0, 0, 0);
	ObjText_SetFontBorderWidth(objText, 1);
	Obj_SetRenderPriority(objText, 0.6);
	ObjText_SetMaxWidth(objText, 300);
	ObjText_SetAutoTransCenter(objText, true );
	ObjRender_SetX(objText, GetStgFrameHeight()/2-150-40);
	ObjRender_SetY(objText, 98);
	//DelaySE("SSpell3",0,10,0);
	loop(120)
	{
		yield;
	}
	Obj_Delete(objText);
}

//----------------------------------------------------
//----------------------------------------------------
task TCurrentFps()
{
	let objText = ObjText_Create();
	ObjText_SetFontSize(objText, 20);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontType(objText, "Cirno");
	ObjText_SetFontColorTop(objText, 160, 160, 200);
	ObjText_SetFontColorBottom(objText, 64, 64, 100);
	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, 0);
	ObjRender_SetY(objText, GetScreenHeight() - 25);

	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_SetFontType(objText, "Cirno");
	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;
}

function GetNumSize(value){
	let numsize = 1;
	value = truncate(value);
	if(value>=10&&value<100){numsize = 2;}
	if(value>=100&&value<1000){numsize = 3;}
	if(value>=1000&&value<10000){numsize = 4;}
	if(value>=10000&&value<100000){numsize = 5;}
	if(value>=100000&&value<1000000){numsize = 6;}
	if(value>=1000000&&value<10000000){numsize = 7;}
	if(value>=10000000&&value<100000000){numsize = 8;}
	if(value>=100000000&&value<1000000000){numsize = 9;}
	if(value>=1000000000&&value<10000000000){numsize = 10;}
	if(value>=10000000000&&value<100000000000){numsize = 11;}
	if(value>=1000000000000){numsize = 12;}
	return numsize;
}