let dirCurrent = GetCurrentScriptDirectory();
let alpha = 0;
let quality = 2;

@Initialize{
	InstallFont(dirCurrent ~ "./../Fonts/Blogger Sans.ttf");
	InstallFont(dirCurrent ~ "./Blogger Sans-Bold.ttf");
	SetPauseScriptPath(dirCurrent ~ "Miyako_Pause.txt");
	SetEndSceneScriptPath(dirCurrent ~ "Miyako_EndScene.txt");
	InitFrame();
	TScore();
	THighScore();
	
	TTextLife;
	TTextBomb;
	
	TTextPower;
	TGraze;
	TCoins;
	MaxBomb();
	MaxLife();
	BossLife();
	TBossTimer();
	TCurrentFps();
	TReplayFps();
	
	TCoinEffect;}

@MainLoop{
	PlayerLife();
	TPlayerSpell();
	yield;}

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

task InitFrame(){
	let path = GetCurrentScriptDirectory() ~ "img/StgBackground.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 1067, 800);
	ObjSprite2D_SetDestRect(obj, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
loop(10){yield;}
	let objGraze = ObjText_Create();
	if(GetCommonData("Word",0) == 0){ObjText_SetText(objGraze, "Extra");}
	if(GetCommonData("Word",0) == 1){ObjText_SetText(objGraze, "Ultra");}
	ObjText_SetFontSize(objGraze, 22);
	ObjText_SetFontType(objGraze,"Blogger Sans");
	ObjText_SetFontColorTop(objGraze, 255, 255, 255);
	ObjText_SetFontColorBottom(objGraze, 255, 255, 255);
	Obj_SetRenderPriority(objGraze,0.99);
	ObjRender_SetX(objGraze, 540);
	ObjRender_SetY(objGraze, 65);}

task TScore(){
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, "Score");
	ObjText_SetFontSize(objScore, 20);
	ObjText_SetFontType(objScore,"Blogger Sans");
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 128, 64);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,25, 25, 25);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.9);
	ObjRender_SetX(objScore, 436);
	ObjRender_SetY(objScore, 118);

	let objGraze = ObjText_Create();
	ObjText_SetText(objGraze, "Miyako Yahouou");
	ObjText_SetFontSize(objGraze, 35);
	ObjText_SetFontType(objGraze,"Blogger Sans");
	ObjText_SetFontColorTop(objGraze, 255, 255, 255);
	ObjText_SetFontColorBottom(objGraze, 255, 255, 255);
	Obj_SetRenderPriority(objGraze,0.9);
	ObjRender_SetX(objGraze, 435);
	ObjRender_SetY(objGraze, 30);

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

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	Obj_SetRenderPriority(obj, 0.9);
	ObjRender_SetY(obj,115);

	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, 484 + iObj * 12);
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 0, (num + 1) * 16, 26);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 26);
			ObjSpriteList2D_AddVertex(obj);}
		yield;}}

task THighScore(){
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, "Record");
	ObjText_SetFontSize(objScore, 20);
	ObjText_SetFontType(objScore,"Blogger Sans");
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 128, 64);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore, 25, 25, 25);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.9);
	ObjRender_SetX(objScore, 425);
	ObjRender_SetY(objScore, 94);

	CreateCommonDataArea("RECORDS");
	let loaded = LoadCommonDataAreaA2("RECORDS",GetCurrentScriptDirectory ~ "./records.dat");
	if(!loaded){
		SetAreaCommonData("RECORDS","HIGH_SCORE",0);}

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

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	Obj_SetRenderPriority(obj, 0.9);
	ObjRender_SetY(obj,90);

	while(true){
		let score = GetAreaCommonData("RECORDS","HIGH_SCORE",0);
		score = min(score, 999999999999);
		let listNum = DigitToArray(score, count);
		ObjSpriteList2D_ClearVertexCount(obj);
			if(GetScore() > GetAreaCommonData("RECORDS","HIGH_SCORE",0)){
				SetAreaCommonData("RECORDS","HIGH_SCORE",GetScore());}
		ascent(iObj in 0 .. count){
			let num = listNum[iObj];
			ObjRender_SetX(obj, 484 + iObj * 12);
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 0, (num + 1) * 16, 26);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 26);
			ObjSpriteList2D_AddVertex(obj);}
		yield;}}

task PlayerLife{
	let space = 0;
	let point = GetPlayerLife();

	loop(point){
		let objL2 = ObjPrim_Create(OBJ_SPRITE_2D);
        let Target = GetCurrentScriptDirectory~"/img/front15.png";
        Obj_SetRenderPriority(objL2,0.01);
		ObjPrim_SetTexture(objL2, Target);
		ObjSprite2D_SetSourceRect(objL2, 992, 0, 1024, 36);
		ObjSprite2D_SetDestCenter(objL2);
		ObjRender_SetX(objL2, 496+space);
		ObjRender_SetY(objL2, 162);
		ObjRender_SetScaleXYZ(objL2,0.5,0.5,0);
        space+=14;
		loop(2){yield}
		Obj_Delete(objL2);}}

task MaxLife{
	let space = 0;
	let objL1 = ObjPrim_Create(OBJ_SPRITE_2D);
	let Target = GetCurrentScriptDirectory~"/img/front15.png";
	Obj_SetRenderPriority(objL1,0.02);
	ObjPrim_SetTexture(objL1, Target);
	ObjRender_SetScaleXYZ(objL1,0.5,0.5,0);
    loop(9){
	let objL2 = ObjPrim_Create(OBJ_SPRITE_2D);
        Obj_SetRenderPriority(objL2,0.01);
		ObjPrim_SetTexture(objL2, Target);
		ObjSprite2D_SetSourceRect(objL2, 832, 0, 864, 36);
		ObjSprite2D_SetDestCenter(objL2);
		ObjRender_SetX(objL2, 496+space);
		ObjRender_SetY(objL2, 162);
		ObjRender_SetScaleXYZ(objL2,0.5,0.5,0);
        space+=14;}
	
	let objScore = ObjText_Create();
	ObjText_SetFontSize(objScore, 14);
	ObjText_SetFontType(objScore,"Blogger Sans");
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 10, 10);
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore, 25, 25, 25);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.9);
	ObjRender_SetX(objScore, 530);
	ObjRender_SetY(objScore, 167);
	
	let spalt = 14;
	let spalt2 = 32;
	CreateCommonDataArea("LIFE");
	LoadCommonDataAreaA1("LIFE");
	loop{
		let point = GetPlayerLife();
		let lifep = GetAreaCommonData("LIFE","Number",0);
		if(point >= 9 || point < 0){
			ObjText_SetText(objScore, "Pieces: 0/5");
			SetAreaCommonData("LIFE","Number",0);
			 spalt = 300; spalt2 = 300;}
		if(lifep >= 5){
			SetAreaCommonData("LIFE","Number",0);}
		if(lifep < 5){
			ObjSprite2D_SetSourceRect(objL1, 832 + spalt2 * lifep, 0, 864 + spalt2 * lifep, 36);
			ObjSprite2D_SetDestCenter(objL1);
			ObjRender_SetX(objL1, 496+spalt*point);
			ObjRender_SetY(objL1, 162);
		
			let text = "Pieces: " ~ vtos("1.0f", lifep) ~ "/5";
			ObjText_SetText(objScore, text);
			spalt = 14; spalt2 = 32;}
		yield;}}

task TTextLife{
	let objGraze = ObjText_Create();
	ObjText_SetText(objGraze, "Life");
	ObjText_SetFontSize(objGraze, 20);
	ObjText_SetFontType(objGraze,"Blogger Sans");
	ObjText_SetFontBold(objGraze, true);
	ObjText_SetFontColorTop(objGraze, 255, 255, 255);
	ObjText_SetFontColorBottom(objGraze, 255, 64, 64);
	ObjText_SetFontBorderType(objGraze, BORDER_FULL);
	ObjText_SetFontBorderColor(objGraze, 25, 25, 25);
	ObjText_SetFontBorderWidth(objGraze, 1);
	Obj_SetRenderPriority(objGraze,0.9);
	ObjRender_SetX(objGraze, 448);
	ObjRender_SetY(objGraze, 150);
	let space = 0;}

task TTextPower{
	let objGraze = ObjText_Create();
	ObjText_SetText(objGraze, "Power");
	ObjText_SetFontSize(objGraze, 20);
	ObjText_SetFontType(objGraze,"Blogger Sans");
	ObjText_SetFontBold(objGraze, true);
	ObjText_SetFontColorTop(objGraze, 255, 255, 255);
	ObjText_SetFontColorBottom(objGraze, 64, 64, 255);
	ObjText_SetFontBorderType(objGraze, BORDER_FULL);
	ObjText_SetFontBorderColor(objGraze, 25, 25, 25);
	ObjText_SetFontBorderWidth(objGraze, 1);
	Obj_SetRenderPriority(objGraze,0.9);
	ObjRender_SetX(objGraze, 430);
	ObjRender_SetY(objGraze, 200);

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

	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, 200);
	ObjRender_SetX(obj, 490);}

task TPlayerSpell{
	let space = 0;
	let point = GetPlayerSpell();
	loop(point){
		let objL2 = ObjPrim_Create(OBJ_SPRITE_2D);
        let Target = GetCurrentScriptDirectory ~ "/img/front15.png";
        Obj_SetRenderPriority(objL2,0.01);
		ObjPrim_SetTexture(objL2, Target);
		ObjSprite2D_SetSourceRect(objL2, 992, 40, 1024, 76);
		ObjRender_SetScaleXYZ(objL2, 0.5, 0.5, 0);
		ObjSprite2D_SetDestCenter(objL2);
		ObjRender_SetX(objL2, 496+space);
		ObjRender_SetY(objL2, 187);
        space+=14;
		loop(2){yield}
		Obj_Delete(objL2);}}

task MaxBomb{
	let space = 0;
	let objL1 = ObjPrim_Create(OBJ_SPRITE_2D);
	let Target = GetCurrentScriptDirectory~"/img/front15.png";
	Obj_SetRenderPriority(objL1,0.02);
	ObjPrim_SetTexture(objL1, Target);
	ObjRender_SetScaleXYZ(objL1, 0.5, 0.5, 0);

	loop(9){
		let objL2 = ObjPrim_Create(OBJ_SPRITE_2D);
		Obj_SetRenderPriority(objL2,0.01);
		ObjPrim_SetTexture(objL2, Target);
		ObjSprite2D_SetSourceRect(objL2, 832, 40, 864, 76);
		ObjSprite2D_SetDestCenter(objL2);
		ObjRender_SetX(objL2, 496+space);
		ObjRender_SetY(objL2, 187);
		ObjRender_SetScaleXYZ(objL2, 0.5, 0.5, 0);
        space+=14;}

	let objScore = ObjText_Create();
	ObjText_SetFontSize(objScore, 14);
	ObjText_SetFontType(objScore,"Blogger Sans");
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 10, 128, 10);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore, 25, 25, 25);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.9);
	ObjRender_SetX(objScore, 530);
	ObjRender_SetY(objScore, 194);

	let spalt = 14;
	let spalt2 = 32;
	CreateCommonDataArea("SPELL");
	LoadCommonDataAreaA1("SPELL");
	loop{
		let point = GetPlayerSpell();
		let spellp = GetAreaCommonData("SPELL","Number",0);
		if(point >= 9 || point < 0){
			ObjText_SetText(objScore, "Pieces: 0/5");
			SetAreaCommonData("SPELL","Number",0);
			 spalt = 300; spalt2 = 300;}
		if(spellp >= 5){
			SetAreaCommonData("SPELL","Number",0);}
		if(spellp < 5){
			ObjSprite2D_SetSourceRect(objL1, 832 + spalt2 * spellp, 40, 864 + spalt2 * spellp, 76);
			ObjSprite2D_SetDestCenter(objL1);
			ObjRender_SetX(objL1, 496+spalt*point);
			ObjRender_SetY(objL1, 187);
		
			let text = "Pieces: " ~ vtos("1.0f", spellp) ~ "/5";
			ObjText_SetText(objScore, text);
			spalt = 14; spalt2 = 32;}
		yield;}}

task TTextBomb{
	let objGraze = ObjText_Create();
	ObjText_SetText(objGraze, "Spell");
	ObjText_SetFontSize(objGraze, 20);
	ObjText_SetFontType(objGraze,"Blogger Sans");
	ObjText_SetFontBold(objGraze, true);
	ObjText_SetFontColorTop(objGraze, 255, 255, 255);
	ObjText_SetFontColorBottom(objGraze, 32, 128, 32);
	ObjText_SetFontBorderType(objGraze, BORDER_FULL);
	ObjText_SetFontBorderColor(objGraze,25, 25, 25);
	ObjText_SetFontBorderWidth(objGraze, 1);
	Obj_SetRenderPriority(objGraze,0.9);
	ObjRender_SetX(objGraze, 440);
	ObjRender_SetY(objGraze, 175);}

task TGraze{
	let objGraze = ObjText_Create();
	ObjText_SetText(objGraze, "Graze");
	ObjText_SetFontSize(objGraze, 20);
	ObjText_SetFontType(objGraze,"Blogger Sans");
	ObjText_SetFontBold(objGraze, true);
	ObjText_SetFontColorTop(objGraze, 255, 255, 255);
	ObjText_SetFontColorBottom(objGraze, 255, 128, 64);
	ObjText_SetFontBorderType(objGraze, BORDER_FULL);
	ObjText_SetFontBorderColor(objGraze,64,25,25);
	ObjText_SetFontBorderWidth(objGraze, 1);
	Obj_SetRenderPriority(objGraze,0.9);
	ObjRender_SetX(objGraze, 434);
	ObjRender_SetY(objGraze, 240);

	let pathDigit = GetCurrentScriptDirectory() ~ "img/Number.png";
	let count = 5;

	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, 240);

	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, 484 + iObj * 12);
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 0, (num + 1) * 16, 26);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 26);
			ObjSpriteList2D_AddVertex(obj);}
		yield;}}

task TCoinEffect{
	let path = GetCurrentScriptDirectory ~ "./../Functions/Coin.mqo";
	let obj = ObjMesh_Create();
	ObjMesh_Load(obj, path);
	ObjMesh_SetCoordinate2D(obj,true);

	ObjRender_SetPosition(obj,550,406,0);
	ObjRender_SetScaleXYZ(obj,0.4,0.4,0.4);
	Obj_SetRenderPriority(obj,0.9);
	ObjRender_SetAngleZ(obj,90);
	ObjRender_SetAngleX(obj,54);
	let color = 0;
	let y = 0;
	loop{
		ObjRender_SetAngleY(obj,y);
		ObjMesh_SetColor(obj,250,180+70*sin(y),64);
		if(y>=360){y=0;}
		y+=3; yield;}}

task TCoins{
	let objGraze = ObjText_Create();
	ObjText_SetText(objGraze, "Coins");
	ObjText_SetFontSize(objGraze, 20);
	ObjText_SetFontType(objGraze,"Blogger Sans");
	ObjText_SetFontBold(objGraze, true);
	ObjText_SetFontColorTop(objGraze, 255, 255, 255);
	ObjText_SetFontColorBottom(objGraze, 255, 128, 64);
	ObjText_SetFontBorderType(objGraze, BORDER_FULL);
	ObjText_SetFontBorderColor(objGraze,25,25,25);
	ObjText_SetFontBorderWidth(objGraze, 1);
	Obj_SetRenderPriority(objGraze,0.9);
	ObjRender_SetX(objGraze, 434);
	ObjRender_SetY(objGraze, 400);

	let objScore = ObjText_Create();
	ObjText_SetFontSize(objScore, 20);
	ObjText_SetFontType(objScore,"Blogger Sans");
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 255, 255);
	Obj_SetRenderPriority(objScore, 0.9);
	ObjRender_SetX(objScore, 488);
	ObjRender_SetY(objScore, 400);
	
	let objScore1 = ObjText_Create();
	ObjText_SetText(objScore1, "");	
	ObjText_SetFontSize(objScore1, 20);
	ObjText_SetFontType(objScore1,"Blogger Sans");
	ObjText_SetFontColorTop(objScore1, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore1, 255, 255, 255);
	Obj_SetRenderPriority(objScore1, 0.9);
	ObjRender_SetX(objScore1, 484);
	ObjRender_SetY(objScore1, 425);

	CreateCommonDataArea("COINS");						
	LoadCommonDataAreaA1("COINS");
	
	let fruit = GetAreaCommonData("COINS","Number",0);
	loop{
		fruit = GetAreaCommonData("COINS","Number",0);
		let text = vtos("1.0f", fruit) ~ " /10";
		ObjText_SetText(objScore, text);
			if(GetAreaCommonData("ULTRA","PATH",0) == 1){
				ObjText_SetText(objScore1, "Ultra mode unlocked");}
			if(GetAreaCommonData("COINS","Number",0) >= 10){break;}
		yield;}}

task BossLife{
	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, -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 = 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*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.13)*cos(angle-90);
			y = (maxRadius*1.13)*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.13)*cos(angle-90);
			y = (maxRadius*1.13)*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 pathDigit = GetCurrentScriptDirectory() ~ "img/Number.png";

	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, 0);
	let count = 2;
   
	let objScene = ID_INVALID;
	let t = csd~"./se/se_timeout.wav";
	LoadSound(t);
	loop{
		objScene = GetEnemyBossSceneObjectID();
		ObjSpriteList2D_ClearVertexCount(obj);
		if(objScene != ID_INVALID){
			RenderTimer();
		 if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER) > 10){
		   ObjRender_SetColor(obj,255,255,255);}
	
		   if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER)<=10){
		   ObjRender_SetColor(obj,255,120,0);
		   LoadSound(t);
                   PlaySE(t);
                   loop(60){yield;}}
		   if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER)<=3){
		   ObjRender_SetColor(obj,255,20,0);
		   t = csd~"./se/se_timeout2.wav";}}
		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,iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 0, (num + 1) * 16, 26);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			ObjSpriteList2D_AddVertex(obj);}}}

task TGainSpell(score){
	let  csd = GetCurrentScriptDirectory;
	let gain = csd~"./se/se_cardget.wav";
	LoadSound(gain);
	let objL2 = ObjPrim_Create(OBJ_SPRITE_2D);
        let Target = GetCurrentScriptDirectory~"/img/front00.png";
        Obj_SetRenderPriority(objL2, 3);
	ObjPrim_SetTexture(objL2, Target);
	ObjRender_SetBlendType(objL2, BLEND_ALPHA);
	ObjSprite2D_SetSourceRect(objL2, 9, 98, 227, 125);
	ObjSprite2D_SetDestCenter(objL2);
        ObjRender_SetScaleXYZ(objL2, 1, 1, 1);
	ObjRender_SetX(objL2, 232);
	ObjRender_SetY(objL2, 140);

	let strScore = "+" ~ IntToString(score);
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Number.png";
	let count = 8;
		PlaySE(gain);
		let objScene = GetEnemyBossSceneObjectID();
	AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 1);
	ObjRender_SetY(obj, 152);
	let a = 255;

	while(true){
		let graze = score;
		graze = min(graze, 99999999);
		let listNum = DigitToArray(graze, count);
               a--;
            
		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count){
			let num = listNum[iObj];
			ObjRender_SetX(obj, 170 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 0, (num + 1) * 16, 26);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			ObjSpriteList2D_AddVertex(obj);}
		yield;
	loop(120){yield;}

	Obj_Delete(objL2);
	Obj_Delete(obj);}}

task TCurrentFps(){
	let objText = ObjText_Create();
	ObjText_SetFontSize(objText, 14);
	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,200, 100, 32);
	ObjText_SetFontBorderWidth(objText, 2);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objText, GetScreenWidth() - 8);
	Obj_SetRenderPriority(objText, 0.9);
	ObjRender_SetX(objText, 0);
	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;}}

task BonusPoint{
	let img_effect2 = GetCurrentScriptDirectory~"./../Image/effect2.png";
		let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		let count = 0;
		let bonus = 10;
		ObjPrim_SetTexture(obj, img_effect2);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.8);
		loop{
			ObjSpriteList2D_ClearVertexCount(obj);
			ObjRender_SetAlpha(obj, 255);
			
			ObjSpriteList2D_SetSourceRect(obj, 0, 95, 128, 107);
			ObjSpriteList2D_SetDestCenter(obj);
			ObjRender_SetPosition(obj, 36, 36, 0);
			ObjSpriteList2D_AddVertex(obj);
			
			let objScene = GetEnemyBossSceneObjectID;
			bonus = min(99999999, ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
			count = GetNumSize(bonus);
			let listNum = DigitToArray(bonus, count);
			
			//Bonus Score
			if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) +
			ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0){
				ascent(iObj in 0 .. count){
					let num = listNum[iObj];
					ObjRender_SetX(obj, GetStgFrameWidth-94-(8*count) + iObj * 7);
					ObjSpriteList2D_SetSourceRect(obj, num * 8, 112, (num + 1) * 8, 124);
					ObjSpriteList2D_SetDestCenter(obj);
					ObjSpriteList2D_AddVertex(obj);
				}
			}else{
					ObjRender_SetX(obj, GetStgFrameWidth-131);
					ObjSpriteList2D_SetSourceRect(obj, 144, 95, 176, 107);
					ObjSpriteList2D_SetDestCenter(obj);
					ObjSpriteList2D_AddVertex(obj);
			}
		Obj_Delete(obj);}}

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))}