let dirCurrent = GetCurrentScriptDirectory();
let path = GetCurrentScriptDirectory() ~ "img/front16.png";
let path2 = GetCurrentScriptDirectory() ~ "img/front16en.png";
let pathDigit = GetCurrentScriptDirectory() ~ "img/ascii.png";
let pathScore = GetCurrentScriptDirectory() ~ "/img/front00.png";
let alpha = 0;
let quality = 2;

@Initialize{
	SetPauseScriptPath(dirCurrent ~ "pause.txt");
	SetEndSceneScriptPath(dirCurrent ~ "end_scene.txt");
	SetReplaySaveSceneScriptPath(dirCurrent ~ "replay_save_scene.txt");
	InitFrame();
	TScore();
	THighScore();

	TGraze;
	TSample;
	TBossLife();
	TBossTimer();
	TCurrentFps();
	TReplayFps();}

@MainLoop{yield;}

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

task InitFrame(){
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj1, path);
	Obj_SetRenderPriority(obj1, 0);
	ObjSprite2D_SetSourceRect(obj1, 64, 0, 512, 960);
	ObjSprite2D_SetDestRect(obj1, 416, 0, 640, 480);

	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj2, path);
	Obj_SetRenderPriority(obj2, 0);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, 64, 960);
	ObjSprite2D_SetDestRect(obj2, 0, 0, 32, 480);

	let obj3 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj3, path);
	Obj_SetRenderPriority(obj3, 0);
	ObjSprite2D_SetSourceRect(obj3, 0, 992, 768, 1024);
	ObjSprite2D_SetDestRect(obj3, 32, 464, 416, 480);

	let obj4 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj4, path);
	Obj_SetRenderPriority(obj4, 0);
	ObjSprite2D_SetSourceRect(obj4, 0, 960, 768, 992);
	ObjSprite2D_SetDestRect(obj4, 32, 0, 416, 16);
	//Value
	CreateFalseNumber(0,608,204,0, 150,150,255);
	//Power
	CreateFalseNumber(4,540,184,0, 255,150,150);
	CreateFalseNumber(11,550,184,0, 255,150,150);
	
	CreateFalseNumber(0,560,190,-6, 255,150,150);
	CreateFalseNumber(0,566,190,-6, 255,150,150);
	
	CreateFalseNumber(10,572,184,0, 255,150,150);
	
	CreateFalseNumber(4,586,184,0, 255,150,150);
	CreateFalseNumber(11,596,184,0, 255,150,150);
	
	CreateFalseNumber(0,606,190,-6, 255,150,150);
	CreateFalseNumber(0,612,190,-6, 255,150,150);
	
	task CreateFalseNumber(num,x,y,size,r,g,b){
		let objN = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objN, pathDigit);
		Obj_SetRenderPriorityI(objN, 99);
		ObjSprite2D_SetSourceRect(objN, 32*num, 288, 32*(num+1), 288+32);
		ObjSprite2D_SetDestRect(objN, x, y, x+16+size, y+16+size);
		ObjRender_SetColor(objN,r,g,b);
		TAnimation(objN,60);
	}}

task TAnimation(obj,time){
	let alpha = 0;
	ObjRender_SetAlpha(obj,alpha);
	loop(time){yield;}
	loop(45){
		ObjRender_SetAlpha(obj,alpha);
		alpha+=255/45;
		yield;}
	}

task TScore(){
	//Spell
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj2, path2);
	Obj_SetRenderPriorityI(obj2, 99);
	ObjSprite2D_SetSourceRect(obj2, 640, 0, 800, 36);
	ObjSprite2D_SetDestRect(obj2, 422, 134, 422+160/1.8, 134+36/1.8);
	TAnimation(obj2,30);
	//Life
	let obj3 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj3, path2);
	Obj_SetRenderPriorityI(obj3, 99);
	ObjSprite2D_SetSourceRect(obj3, 512, 72, 640, 108);
	ObjSprite2D_SetDestRect(obj3, 430, 94, 430+128/1.8, 94+36/1.8);
	TAnimation(obj3,25);
	//Score
	let obj4 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj4, path2);
	Obj_SetRenderPriorityI(obj4, 99);
	ObjSprite2D_SetSourceRect(obj4, 512, 36, 640, 72);
	ObjSprite2D_SetDestRect(obj4, 430, 62, 430+128/1.8, 62+36/1.8);
	TAnimation(obj4,20);
	
	Dummy(541,66);Dummy(581,66);Dummy(541,46);Dummy(581,46); Dummy(578,228);
	Disabled(400,80);Disabled(400,118);
	let count = 9;
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	Obj_SetRenderPriorityI(obj, 99);
	ObjRender_SetY(obj,63);
	TAnimation(obj,60);

	while(true){
		let score = GetScore();
		score = min(score, 999999999999);
		let listNum = DigitToArray(score, count);
		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0..9){
			let num = listNum[iObj];
			ObjRender_SetX(obj, 508 + iObj*11 + floor((iObj)/3)*6);
			ObjSpriteList2D_SetSourceRect(obj, num * 32, 288, (num + 1) * 32, 288+32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj);}
		yield;}

	task Dummy(x,y){
		let obj0 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj0, pathDigit);
		Obj_SetRenderPriorityI(obj0, 99);
		ObjSprite2D_SetSourceRect(obj0, 352+32*3, 288, 352+32*4, 288+32);
		ObjSprite2D_SetDestRect(obj0, x, y, x+16, y+16);
		TAnimation(obj0,60);}
	task Disabled(x,y){
		let obj0 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj0, path);
		Obj_SetRenderPriorityI(obj0, 99);
		ObjSprite2D_SetSourceRect(obj0, 512, 840, 1024, 930);
		ObjSprite2D_SetDestRect(obj0, x, y, x+512/2, y+90/2);}}

task THighScore(){
	//Power
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj1, path2);
	Obj_SetRenderPriorityI(obj1, 99);
	ObjSprite2D_SetSourceRect(obj1, 660, 108, 800, 144);
	ObjSprite2D_SetDestRect(obj1, 448, 182, 448+140/1.8, 182+36/1.8);
	TAnimation(obj1,35);
	//Value
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj2, path2);
	Obj_SetRenderPriorityI(obj2, 99);
	ObjSprite2D_SetSourceRect(obj2, 660, 72, 800, 108);
	ObjSprite2D_SetDestRect(obj2, 448, 202, 448+140/1.8, 202+36/1.8);
	TAnimation(obj2,40);
	//Graze
	let obj3 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj3, path2);
	Obj_SetRenderPriorityI(obj3, 99);
	ObjSprite2D_SetSourceRect(obj3, 640, 36, 800, 72);
	ObjSprite2D_SetDestRect(obj3, 438, 222, 438+160/1.8, 222+36/1.8);
	TAnimation(obj3,45);
	//Hi-Score
	let obj4 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj4, path2);
	Obj_SetRenderPriorityI(obj4, 99);
	ObjSprite2D_SetSourceRect(obj4, 512, 0, 640, 36);
	ObjSprite2D_SetDestRect(obj4, 430, 40, 430+128/1.8, 40+36/1.8);
	TAnimation(obj4,15);

	CreateCommonDataArea("HiScore");
	let dataFile = dirCurrent ~ "./../resource/data/hiscore.dat";
	let loaded = LoadCommonDataAreaA2("HiScore",dataFile);
	if(!loaded){
		SetAreaCommonData("HiScore","Night1",0);
		SetAreaCommonData("HiScore","Night2",0);}

	let count = 9;
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	Obj_SetRenderPriorityI(obj, 0.9);
	ObjRender_SetColor(obj, 180, 180, 180);
	ObjRender_SetY(obj,42);
	TAnimation(obj,60);
	let score = 0;
	
	while(true){
		if(GetCommonData("BOSS","") == "Eternity"){score = GetAreaCommonData("HiScore","Night1",0);}
		if(GetCommonData("BOSS","") == "Nemuno"){score = GetAreaCommonData("HiScore","Night1",0);}
		if(GetCommonData("BOSS","") == "Aunn"){score = GetAreaCommonData("HiScore","Night2",0);}
		if(GetCommonData("BOSS","") == "Lily"){score = GetAreaCommonData("HiScore","Night2",0);}
		score = min(score, 999999999999);
		let listNum = DigitToArray(score, count);
		ObjSpriteList2D_ClearVertexCount(obj);
			if(GetScore() > score){
				if(GetCommonData("BOSS","") == "Eternity"){SetAreaCommonData("HiScore","Night1",GetScore());}
				if(GetCommonData("BOSS","") == "Nemuno"){SetAreaCommonData("HiScore","Night1",GetScore());}
				if(GetCommonData("BOSS","") == "Aunn"){SetAreaCommonData("HiScore","Night2",GetScore());}
				if(GetCommonData("BOSS","") == "Lily"){SetAreaCommonData("HiScore","Night2",GetScore());}
			}
		ascent(iObj in 0 .. count){
			let num = listNum[iObj];
			ObjRender_SetX(obj, 508 + iObj*11 + floor((iObj)/3)*6);
			ObjSpriteList2D_SetSourceRect(obj, num * 32, 288, (num + 1) * 32, 288+32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj);}
		yield;}
}

task TSample{
	let space = 0;
	ascent(i in 0..8){
		let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
		Obj_SetRenderPriorityI(obj1, 98);
		ObjPrim_SetTexture(obj1, path);
		ObjSprite2D_SetSourceRect(obj1, 832, 0, 864, 32);
		ObjSprite2D_SetDestRect(obj1, 508+14*i, 96, 508+16+14*i, 96+16);

		let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
		Obj_SetRenderPriorityI(obj2, 98);
		ObjPrim_SetTexture(obj2, path);
		ObjSprite2D_SetSourceRect(obj2, 832, 40, 864, 76);
		ObjSprite2D_SetDestRect(obj2, 508+14*i, 136, 508+16+14*i, 136+16);
        }}

task TGraze{
	let count = 4;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	Obj_SetRenderPriorityI(obj, 99);
	ObjRender_SetY(obj, 224);
	TAnimation(obj,60);

	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, 566 + iObj*12 + floor((iObj+2)/3)*6);
			ObjSpriteList2D_SetSourceRect(obj, num * 32, 288, (num + 1) * 32, 288+32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj);}
		yield;}}

task TBossLife{
	let path = GetCurrentScriptDirectory ~ "img/lifebar.png";
	let countVertex = 74;
	let objScene = ID_INVALID;
	
	let objStar = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(objStar, GetCurrentScriptDirectory ~ "img/frame2.png");
	Obj_SetRenderPriority(objStar, 0.7);
	ObjSpriteList2D_SetSourceRect(objStar, 144, 80, 156, 92);

	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, -5, 2.5, 5);

	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 = 64;

	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, 0, 18, 0);

	while(GetCommonData("quality", 2)==quality){
		ObjSpriteList2D_ClearVertexCount(objStar);
		ObjSpriteList2D_ClearVertexCount(objKnub);
		if(GetCommonData("Safe",0) == 0){
			ObjRender_SetAlpha(objStar, min(255, 255*(outlineRender*3)-510));
		}else{
			if(GetPlayerY < max(96, 26+(truncate(countRemStep/12)*12))){
				fade = max(fade-10, 85);
			}else{fade = min(fade+10, 255);}
			ObjRender_SetAlpha(objStar, fade);}

		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*0.95)*cos(kang-90);
			let ky = my+(maxRadius*0.95)*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*0.9)*cos(angle-90);
			y = (maxRadius*0.9)*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*0.9)*cos(angle-90);
			y = (maxRadius*0.9)*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  csd = GetCurrentScriptDirectory;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	Obj_SetRenderPriority(obj, 0.75);
	ObjRender_SetY(obj, 0);

	let obj2 = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj2, pathDigit);
	Obj_SetRenderPriority(obj2, 0.75);
	ObjRender_SetY(obj2, 9);

	let obj3 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj3, pathDigit);
	ObjSprite2D_SetSourceRect(obj3, 352, 288, 352+32, 288+32);
	ObjSprite2D_SetDestRect(obj3, 202, 0, 202+20, 20);
	Obj_SetRenderPriority(obj3, 0.75);

	let time = 0;
	let count = 3;
	let second = 99;
	let x = 175-14;
   
	let objScene = ID_INVALID;
	let t = csd~"./se/se_timeout.wav";
	LoadSound(t);
	loop{
		objScene = GetEnemyBossSceneObjectID();
		ObjSpriteList2D_ClearVertexCount(obj);
		ObjSpriteList2D_ClearVertexCount(obj2);

		if(objScene != ID_INVALID){
			RenderTimer();
		if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER) > 10){
		   ObjRender_SetColor(obj,255,255,255);
		   ObjRender_SetColor(obj2,255,255,255);
		   ObjRender_SetColor(obj3,255,255,255);}
	
		if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER) <= 10){
			ObjRender_SetColor(obj,255,120,0);
			ObjRender_SetColor(obj2,255,120,0);
			ObjRender_SetColor(obj3,255,120,0);
			LoadSound(t);
			if(time % 60 == 0){
				PlaySE(t);}
			time++;}
		if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER) <= 3){
			ObjRender_SetColor(obj,255,20,0);
			ObjRender_SetColor(obj2,255,20,0);
			ObjRender_SetColor(obj3,255,20,0);
			t = csd~"./se/se_timeout2.wav";}
		if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER) <= 0 || 
			ObjEnemyBossScene_GetInfo(objScene, INFO_CURRENT_LIFE) <= 1){
			Obj_Delete(obj3);}}
		if(second<=0){second = 99;}
		second-=99/60;
		yield;}

	function RenderTimer(){
		let timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER);
		let listNum = DigitToArray(timer, count);
		let listNum2 = DigitToArray(second, 2);
		if(timer > 99){ count = 3; x = 175-14; }
		if(timer <= 99){ count = 2; x = 175;}

		ObjSpriteList2D_ClearVertexCount(obj);
		ObjSpriteList2D_ClearVertexCount(obj2);
		ascent(iObj in 0 .. count){
			let num = listNum[iObj];
			ObjRender_SetX(obj,x + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 32, 288, (num + 1) * 32, 288+32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 20, 20);
			ObjSpriteList2D_AddVertex(obj);
			}
		ascent(iObj in 0 .. 2){
			let num = listNum2[iObj];
			ObjRender_SetX(obj2,212 + iObj * 7);
			ObjSpriteList2D_SetSourceRect(obj2, num * 32, 288, (num + 1) * 32, 288+32);
			ObjSpriteList2D_SetDestRect(obj2, 0, 0, 10, 10);
			ObjSpriteList2D_AddVertex(obj2);
			}}}

task TGainSpell(score){
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
    	Obj_SetRenderPriorityI(obj1, 70);
	ObjPrim_SetTexture(obj1, path);
	ObjSprite2D_SetSourceRect(obj1, 512, 188, 1024, 260);
	ObjSprite2D_SetDestRect(obj1, 50, 120, 50+512/1.6, 120+72/1.6);
	//line
	let obj3 = ObjPrim_Create(OBJ_SPRITE_2D);
    	Obj_SetRenderPriorityI(obj3, 70);
	ObjPrim_SetTexture(obj3, path);
	ObjSprite2D_SetSourceRect(obj3, 512, 570, 844, 590);
	ObjSprite2D_SetDestRect(obj3, 150, 202, 150+332/2, 202+16);

	let objN = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objN, pathDigit);
	Obj_SetRenderPriorityI(objN, 99);
	ObjSprite2D_SetSourceRect(objN, 255, 322, 272, 340);
	ObjSprite2D_SetDestRect(objN, 306, 194, 306+17, 194+18);

	let objText = ObjText_Create();
	ObjText_SetText(objText, "Score:[r]Graze x Time:");
	ObjText_SetFontSize(objText, 20);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontType(objText,"Blogger Sans");
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,10, 10, 10);
	ObjText_SetFontBorderWidth(objText, 1);
	Obj_SetRenderPriorityI(objText, 99);
	ObjRender_SetX(objText, 50);
	ObjRender_SetY(objText, 180);

	//let strScore = "+" ~ IntToString(score);
	let count = 9;
		
	let objScene = GetEnemyBossSceneObjectID();
	AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
	//score
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	Obj_SetRenderPriorityI(obj, 99);
	ObjRender_SetY(obj, 182);
		let graze = score;
		graze = min(graze, 999999999);
		let listNum = DigitToArray(graze, count);
		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count){
			let num = listNum[iObj];
			ObjRender_SetX(obj, 182 + iObj * 12 + floor((iObj)/3)*6);
			ObjSpriteList2D_SetSourceRect(obj, num * 32, 288, (num + 1) * 32, 288+32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj);}

	//graze x time
	let count2 = 9;
	let obj2 = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj2, pathDigit);
	Obj_SetRenderPriorityI(obj2, 99);
	ObjRender_SetY(obj2, 206);
		let graze2 = GetGraze() * ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER);
		AddScore(graze2);
		graze2 = min(graze2, 999999999);
		let listNum2 = DigitToArray(graze2, count2);
		ObjSpriteList2D_ClearVertexCount(obj2);
		ascent(iObj in 0 .. count2){
			let num = listNum2[iObj];
			ObjRender_SetX(obj2, 182 + iObj * 12 + floor((iObj)/3)*6);
			ObjSpriteList2D_SetSourceRect(obj2, num * 32, 288, (num + 1) * 32, 288+32);
			ObjSpriteList2D_SetDestRect(obj2, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj2);}
			
	//sum
	let count4 = 10;
	let obj4 = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj4, pathDigit);
	Obj_SetRenderPriorityI(obj4, 99);
	ObjRender_SetY(obj4, 236);
		let graze4 = GetGraze() * ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER) + ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE);
		graze4 = min(graze4, 9999999999);
		let listNum4 = DigitToArray(graze4, count4);
		ObjSpriteList2D_ClearVertexCount(obj4);
		ascent(iObj in 0 .. count4){
			let num = listNum4[iObj];
			ObjRender_SetX(obj4, 182 + iObj * 14 + floor((iObj+2)/3)*8);
			ObjSpriteList2D_SetSourceRect(obj4, num * 32, 288, (num + 1) * 32, 288+32);
			ObjSpriteList2D_SetDestRect(obj4, 0, 0, 20, 20);
			ObjSpriteList2D_AddVertex(obj4);}
		ObjSpriteList2D_CloseVertex(obj4);

	loop(10){
		ObjRender_SetAlpha(obj1,100);loop(2){yield;}
		ObjRender_SetAlpha(obj1,255);loop(2){yield;}
	}
	loop(60){yield;}
	let alpha = 255;
	loop(60){
		ObjRender_SetAlpha(obj1,alpha);
		ObjRender_SetAlpha(obj3,alpha);
		ObjRender_SetAlpha(objN,alpha);
		ObjRender_SetAlpha(objText,alpha);
		ascent(i in 0..ObjPrim_GetVertexCount(obj)){ 
			ObjPrim_SetVertexAlpha(obj,i,alpha);}
		ascent(i in 0..ObjPrim_GetVertexCount(obj2)){ 
			ObjPrim_SetVertexAlpha(obj2,i,alpha);}
		ascent(i in 0..ObjPrim_GetVertexCount(obj4)){ 
			ObjPrim_SetVertexAlpha(obj4,i,alpha);}
	alpha-=255/60;
	yield;}
	Obj_Delete(obj);
	Obj_Delete(obj1);
	Obj_Delete(obj2);
	Obj_Delete(obj3);
	Obj_Delete(obj4);
	Obj_Delete(objN);
	Obj_Delete(objText);
}

task TCurrentFps(){
	let objText = ObjText_Create();
	ObjText_SetFontSize(objText, 10);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontType(objText,"Blogger Sans");
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,10, 10, 10);
	ObjText_SetFontBorderWidth(objText, 2);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objText, GetScreenWidth() - 2);
	Obj_SetRenderPriorityI(objText, 99);
	ObjRender_SetX(objText, 0);
	ObjRender_SetY(objText, GetScreenHeight() - 14);

	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, 20);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontType(objText,"Blogger Sans");
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,10, 10, 10);
	ObjText_SetFontBorderWidth(objText, 1);
	Obj_SetRenderPriorityI(objText, 99);

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

function GetNumSize(value){
	if(value<=1){return 1;}
	else{return truncate(log10(value))+1;}}

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 GetDistance(x1,y1,x2,y2){
	return(((x2-x1)^2+(y2-y1)^2)^(1/2))}