
let dirCurrent = GetCurrentScriptDirectory();
SetPauseScriptPath(dirCurrent~"Default_Pause.txt");
SetDefaultBonusItemEnable(false);
StartItemScript(dirCurrent~"/item.txt");
let pause=false;
LoadCommonDataAreaA2("hiscore", GetModuleDirectory~"script/LastBossCollection/data/score.dat");
let t=0;
@Initialize
{	TCurrentFps;

	InitFrame();
	TScore;
	TLifeBack();
	TPlayerLife();
	TBossTimer();
	TReplayFps();
	TBossRemain;
	}

@MainLoop
{
if (GetCommonData("Tstop", 0)==0){
SetForbidPlayerShot(false);
SetForbidPlayerSpell(false);
}
if (t==0){SetPlayerLife(999); t++;}
ClearInvalidRenderPriority;
yield;
}

@Event
{

	alternative(GetEventType())
	
	case(EV_PLAYER_SHOOTDOWN){
	BreakWave(GetPlayerObjectID);
	}
	case(EV_END_BOSS_STEP){
	if (ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_IS_SPELL)){
		let score = GetCommonData("bonus", 0);
		DrawBonus(score);}
	BreakWave(GetEnemyBossObjectID);
	}
	case(EV_START_BOSS_SPELL)
	{
		let path = dirCurrent ~ "Default_System_MagicCircle.txt";
		let id = LoadScript(path);
		StartScript(id);
	}
	case(EV_PAUSE_ENTER){
	
	pause=true;
	}
	case(EV_PAUSE_LEAVE){
	pause=false;
	}
	case(EV_USER+10){
	BossExplosion(GetEventArgument(0)[0], GetEventArgument(0)[1]);
	}
	case(EV_USER+2){ //show the exploding effect
	let arg=GetEventArgument(0);
	Mobplode(arg[0], arg[1], [arg[2], arg[3], arg[4]]);
	}

	
	
}

task TLifeBack
{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriority(obj,0.99);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory() ~ "img/op_03.png");
	ObjSprite2D_SetSourceRect(obj,0,0,460,460);
	ObjSprite2D_SetDestRect(obj,0,0,460,460);
	ObjSprite2D_SetDestCenter(obj);
	//ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,GetScreenWidth+20,-20,0);
	ObjRender_SetScaleXYZ(obj,0.5,0.5,0.5);
	let Alpha = 255;
	let counter = 0;
	while(true)
	{
		ObjRender_SetAngleZ(obj,ObjRender_GetAngleZ(obj)-0.5);
		if(counter>0 && counter<60){counter++;}
		if(counter>=60){counter=0;}
		
		if(GetPlayerY<YAlpha)
		{
			ObjRender_SetAlpha(obj,Alpha);
			if(Alpha>0){Alpha-=255/10;}
		}
		else
		{
			ObjRender_SetAlpha(obj,Alpha);
			if(Alpha<255){Alpha+=255/10;}
		}
		yield;
	}
}


task Mobplode(x, y, rgb){
loop(5){Mobplode02([x, y], [255, 255, 255]);}
yield;
}

task Mobplode02(pos, rgb_h){
		let obj		= ObjPrim_Create(OBJ_SPRITE_2D);
		let cc		= rand(0,360);
		let sca		= rand(0.25, 0.5); let s=sca;
		let dis		= rand(0.5,2);
		let dis1	= 0;
		let ang=rand(0,360); let a=0;
		let alpha=240;
		
		ObjRender_SetPosition(obj,pos[0]+dis1*sin(cc),pos[1]+dis1*cos(cc),0);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"/img/Cherry.png");
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjSprite2D_SetSourceRect(obj,0,0,256,256);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetColor(obj,rgb_h[0],rgb_h[1],rgb_h[2]);
		loop(60){
		ObjRender_SetAngleXYZ(obj,ang,ang,ang);
		ang+=4;
			alpha-=4;
			sca-=s/60;
			dis1+=dis;
			ObjRender_SetPosition(obj,pos[0]+dis1*sin(cc),pos[1]+dis1*cos(cc),0);
			ObjRender_SetScaleXYZ(obj,sca,sca,0);
			ObjRender_SetAlpha(obj, alpha);
			yield;
		}
		Obj_Delete(obj);
}


task TShake(period, intensity)
	{
		loop(period)
		{
			Set2DCameraFocusX(GetStgFrameWidth / 2 + rand(-intensity/2, intensity/2));
			Set2DCameraFocusY(GetStgFrameHeight / 2 + rand(-intensity/2, intensity/2));
			yield;
		}

		Reset2DCamera();
	}

task PlaySoundEffect(sound)
{
let se=ObjSound_Create;
ObjSound_Load(se, GetCurrentScriptDirectory~"se/"~sound~".wav");
ObjSound_SetVolumeRate(se, 40);
ObjSound_Play(se);
}

task BossExplosion(x, y){
PlaySoundEffect("se_enep01");

DeleteShotAll(TYPE_ALL, TYPE_ITEM);
ExplosionRing;
loop(120){
loop(3){Maple(x, y, rand(0,360), rand(3,6));}
loop(1){yield;}}
Obj_SetVisible(GetEnemyBossObjectID, false);
TShake(60, 10);
ExplosionRing;
PlaySoundEffect("se_enep01");
loop(240){
Maple(x, y, rand(0,360), rand(2,5));
}
	task Maple(x, y, angle, speed){
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/Cherry.png");
		ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		ObjSprite2D_SetDestCenter(obj);
		let alpha=240; let s=rand(0.1, 0.5);
		let angle1=rand(0,360); let angle2=rand(0,360);
		loop(120){ObjRender_SetPosition(obj, x, y, 0);
		ObjRender_SetAngleXYZ(obj, angle2, angle1, angle2);
		angle1+=2; angle2+=2; x+=speed*cos(angle); y+=speed*sin(angle);
		s+=0.005; 
		ObjRender_SetScaleXYZ(obj, s, s, 0);
		alpha-=2;
		ObjRender_SetColor(obj, alpha, alpha/2, alpha/2);
		yield;}
		Obj_Delete(obj);
	}
	
	task ExplosionRing{
	let circle=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(circle, GetCurrentScriptDirectory~"/img/ring00.png");
	ObjSprite2D_SetSourceRect(circle, 0, 0, 512, 512);
	ObjSprite2D_SetDestCenter(circle);
	let s=0; let alpha=225;
	ObjRender_SetPosition(circle, x, y, 0);
	let angle=0; ObjRender_SetBlendType(circle, BLEND_ADD_ARGB);
	loop(90){angle+=1; s=1.5*sin(angle); alpha-=2.5; 
	ObjRender_SetColor(circle, alpha, alpha/2, alpha/2);
	ObjRender_SetScaleXYZ(circle, s, s, 0);
	yield;}
	}
}


task TBossRemain
{
	let path = GetCurrentScriptDirectory() ~ "img/life.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0.7);
	ObjRender_SetX(obj,120);
	ObjRender_SetY(obj,-15);
	ObjRender_SetScaleXYZ(obj,0.8,0.8,0.8);
	let lastRemStep = -1;
	let lifeRateRender = 0;
	let alpha=255;
	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;
		}

		//ライフ表示
		if (ObjMove_GetY(GetPlayerObjectID)<64&&ObjMove_GetX(GetPlayerObjectID)<200){if (alpha>100){alpha-=15;}}
		else{if (alpha<255){alpha+=15;}}
		ObjRender_SetAlpha(obj, alpha);
		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);
		let y=0;
		ascent(i in 0..countRemStep){ObjSpriteList2D_SetSourceRect(obj, 16, 16, 32, 32);
		ObjRender_SetColor(obj, 255, 255, 255);
		if (i>6){i-=7; y=6;}
		ObjSpriteList2D_SetDestRect(obj, 6+16*i, 21+y, 6+16+16*i, 21+16+y);
		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 + 448 * (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
{TBossTimerMicro;
	let pathDigit = GetCurrentScriptDirectory() ~ "img/digit.png";

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj, 89);
	let count = 2;
	
	let dot = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(dot, pathDigit);
	Obj_SetRenderPriorityI(dot, 89);
	ObjRender_SetScaleXYZ(dot, 0.7, 0.7, 1);
	let alpha=255;
	ObjRender_SetBlendType(dot, BLEND_ALPHA);

	let objScene = ID_INVALID;
	loop
	{
		objScene = GetEnemyBossSceneObjectID();
		ObjSpriteList2D_ClearVertexCount(obj); ObjSpriteList2D_ClearVertexCount(dot);
		
		if(objScene != ID_INVALID)
		{if(ObjMove_GetY(GetPlayerObjectID)<160){if (alpha>50){alpha-=15;}}else{if (alpha<255){alpha+=15;}}
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetAlpha(dot, alpha);
			RenderTimer();
		}
		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, GetScreenWidth/2-30 + iObj * 18);
			ObjRender_SetY(obj, 0+18);
			ObjSpriteList2D_SetSourceRect(obj, num * 24, 0, (num + 1) * 24, 24);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 24, 24);
			ObjSpriteList2D_AddVertex(obj);
			
			ObjRender_SetX(dot, GetScreenWidth/2+2);
			ObjRender_SetY(dot, 6+18);
			ObjSpriteList2D_SetSourceRect(dot, 14 * 24, 0, (14 + 1) * 24, 24);
			ObjSpriteList2D_SetDestRect(dot, 0, 0, 24, 24);
			ObjSpriteList2D_AddVertex(dot);

		}
	}

}

task TBossTimerMicro
{
			
	let pathDigit = GetCurrentScriptDirectory() ~ "img/digit.png";
let timer = 99;
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.89);
	ObjRender_SetScaleXYZ(obj, 0.7, 0.7, 1);
	let count = 2;
	
	let alpha=255;
			
	let objScene = ID_INVALID;
	loop
	{
		objScene = GetEnemyBossSceneObjectID();
		ObjSpriteList2D_ClearVertexCount(obj);
		if(objScene != ID_INVALID)
		{
		if(ObjMove_GetY(GetPlayerObjectID)<160){if (alpha>50){alpha-=15;}}else{if (alpha<255){alpha+=15;}}
		ObjRender_SetAlpha(obj, alpha);
			RenderTimer();
		}
		yield;
	}

	function RenderTimer()
	{
		if (ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER)<99){
		timer -=100/60; if (timer<0){timer+=100;}}
		else{timer=99;}
		let listNum = DigitToArray(timer, count);
		
		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, GetScreenWidth/2+11 + iObj * 18*0.75);
			ObjRender_SetY(obj, 6+18);
			ObjSpriteList2D_SetSourceRect(obj, num * 24, 0, (num + 1) * 24, 24);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 24, 24);
			ObjSpriteList2D_AddVertex(obj);
		}
	}

}

//----------------------------------------------------
//枠外の背景表示
//----------------------------------------------------


task InitFrame()
{
let obj=ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/frame3.png");
ObjSprite2D_SetSourceRect(obj, 0, 0, 640, 480);
ObjSprite2D_SetDestRect(obj, 0, 0, 640, 480);
Obj_SetRenderPriorityI(obj, 51);
let alpha=255;
SetStgFrame(0, 0, 640, 480, 20, 80); 
loop{
ObjRender_SetAlpha(obj, alpha);
if (GetCommonData("fullscreen", "false")=="true"){SetPlayerClip(0, 0, 640, 480); if (alpha>0){alpha-=15;}}
else{SetPlayerClip(128, 16, 512, 464); alpha=255;}

yield;
}
Obj_Delete(obj);
}


task BreakWave(ID){
let r=0; let shots=[];
let x=ObjMove_GetX(ID); let y=ObjMove_GetY(ID);
while(r<1200){
r+=40;
shots=GetShotIdInCircleA2(x, y, r, TARGET_ENEMY);
ascent(i in 0..length(shots)){
if (!ObjShot_IsSpellResist(shots[i])){
BulletBreak([ObjMove_GetX(shots[i]), ObjMove_GetY(shots[i])],rand(0,360),ObjShot_GetImageID(shots[i]),BLEND_ALPHA);
Obj_Delete(shots[i]);}}
yield;}
}

task BulletBreak(pos,angle,ImgID,Blend){

	let ID		= ObjPrim_Create(OBJ_SPRITE_2D);
	let animC	= 0;
	let anim1	= 0;
	let anim2	= 0;
	let rectX	= 128;
	let rectY	= 128;
	
	ObjRender_SetPosition(ID, pos[0], pos[1], 0 );
	ObjPrim_SetTexture(ID, GetCurrentScriptDirectory~"/img/bulletbreak00.png");
	Obj_SetRenderPriorityI(ID, 40);
	ObjRender_SetBlendType(ID, Blend );
	ObjRender_SetAngleXYZ(ID, 0, 0, rand(0,360) );
	ObjRender_SetAlpha(ID, 192 );
	ObjSprite2D_SetSourceRect(ID, 0 + rectX*anim1, 0 + rectY*anim2, rectX + rectX*anim1, rectY + rectY*anim2 );
	ObjSprite2D_SetDestCenter(ID);
	
	ShotColor(ID, ImgID, Blend );
	
	let sca	= 0.7;
	let pn	= 0;
	if( Blend == BLEND_ADD_ARGB ){
		sca += 0.1;
		ObjRender_SetScaleXYZ(ID, sca, sca, 0 );
	}
	else{
		ObjRender_SetScaleXYZ(ID, sca/1.2, sca/1.2, 0 );
	}
	
	while( anim2 < 2 ){
		ObjSprite2D_SetSourceRect(ID, 0 + rectX*anim1, 0 + rectY*anim2, rectX + rectX*anim1, rectY + rectY*anim2 );
		
		
		animC++;
		if( animC > 0 && animC%3 == 0 ){
			if( anim1 >= 3 ){
				anim1 = 0;
				anim2++;
			}
			anim1++;
		}
		
		yield;
	}
	Obj_Delete(ID);
}



task ShotColor(ID,ImgID,Blend){
let color = GetShotDataInfoA1(ImgID,TARGET_ENEMY,INFO_DELAY_COLOR);
	
	ObjRender_SetColor(ID, color[0], color[1], color[2] );
}

//----------------------------------------------------
//スコア表示
//----------------------------------------------------


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


task DrawBonus(score){
AddScore(score);
let se=ObjSound_Create;
ObjSound_Load(se, GetCurrentScriptDirectory~"system/se/se_cardget.wav");
let rank=0;
if (ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_PLAYER_SHOOTDOWN_COUNT)>1||ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_PLAYER_SPELL_COUNT)>1){rank=0;}
if (ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_PLAYER_SHOOTDOWN_COUNT)==1||(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_PLAYER_SPELL_COUNT)>0&&ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_PLAYER_SHOOTDOWN_COUNT)==0)){rank=1;}
if (ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_PLAYER_SHOOTDOWN_COUNT)==0&&ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_PLAYER_SPELL_COUNT)==0){
if (ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)<=0&&ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_IS_DURABLE_SPELL)==false){rank=2;}
else{rank=3;}}
DrawRank(rank);
let obj=ObjPrim_Create(OBJ_SPRITE_2D);
Obj_SetRenderPriorityI(obj, 60);
ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/frame2.png");
if (score>0){ObjSprite2D_SetSourceRect(obj, 0, 96, 264, 128); ObjRender_SetPosition(obj, GetScreenWidth/2, GetScreenHeight/2-32, 0);
ObjSound_Play(se);}
else{ObjSprite2D_SetSourceRect(obj, 0, 384, 264, 416); ObjRender_SetPosition(obj, GetScreenWidth/2, GetScreenHeight/2, 0);}
ObjSprite2D_SetDestCenter(obj);
let alpha=255; let s=1;
if (score>0){DrawScore;}
loop(30){
s*=-1; alpha=200+55*s;
ObjRender_SetAlpha(obj, alpha);
loop(5){yield;}}
Obj_Delete(obj);

task DrawScore{
let string=IntToString(score);

ascent(i in 0..length(string)){DrawDigit(string[i], i*24); yield;}

task DrawDigit(d, pos){
let digit=ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(digit, GetCurrentScriptDirectory~"/img/digit.png");
Obj_SetRenderPriorityI(digit, 60);
ObjSprite2D_SetSourceRect(digit, d*24, 0, d*24+24, 24);
ObjSprite2D_SetDestCenter(digit);
ObjRender_SetPosition(digit, GetScreenWidth/2-length(string)*12+pos, GetScreenHeight/2, 0);
while(!Obj_IsDeleted(obj)){
ObjRender_SetAlpha(digit, alpha);
yield;}
Obj_Delete(digit);
}

}


}

task DrawRank(rank){
if (rank>0){
ascent(i in 0..rank){SetAreaCommonData("cutin_History", GetAreaCommonData("cutin_History", "Name", "Noname")~IntToString(i), true);}
}
SaveCommonDataAreaA1("cutin_History");
let obj=ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/rank.png");
ObjSprite2D_SetSourceRect(obj, 0, rank*48, 320, rank*48+48);
ObjSprite2D_SetDestCenter(obj);
ObjRender_SetPosition(obj, GetScreenWidth/2+160, GetScreenHeight/2+42, 0);
Obj_SetRenderPriorityI(obj, 60);
let alpha=255; let s=1;
loop(45){
if (rank>1&&s>0){Sparkle;}
s*=-1; alpha=200+55*s;
ObjRender_SetAlpha(obj, alpha);
loop(5){yield;}}
Obj_Delete(obj);

task Sparkle{
let x=ObjRender_GetX(obj)-150+rand(0, 110); let y=ObjRender_GetY(obj)+rand(-20,20);
let star=ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(star, GetCurrentScriptDirectory~"/img/star.png");
ObjSprite2D_SetSourceRect(star, 0, 0, 32, 32);
ObjSprite2D_SetDestCenter(star);
Obj_SetRenderPriorityI(star, 61);
ObjRender_SetPosition(star, x, y, 0);
let angle=0; let size=0;
loop(30){
angle+=6; size=0.5+0.5*sin(angle);
ObjRender_SetScaleXYZ(star, size, size, 1);
yield;}
Obj_Delete(star);
}

}


let YAlpha = 125;
//----------------------------------------------------
//残機表示
//----------------------------------------------------

/*task TPlayerLife
{
	//life文字列
	let objText = ObjText_Create();
	ObjText_SetText(objText, "x");
	ObjText_SetFontSize(objText, 30);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,64, 64, 64);
	ObjText_SetFontBorderWidth(objText, 2);
	ObjText_SetFontType(objText,  "メイリオ");
	Obj_SetRenderPriority(objText, 0.99);
	ObjRender_SetX(objText, 580);
	ObjRender_SetY(objText, 380);
	ObjRender_SetScaleXYZ(objText, 0.7,0.7,0);
	//残機
	let pathDigit = GetCurrentScriptDirectory() ~ "img/ascii_1280.png";
	let count = 3;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	//ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.99);
	ObjText_SetFontBorderType(obj, BORDER_FULL);
	
	
	ObjRender_SetY(obj, GetScreenWidth/2-193);
	ObjRender_SetScaleXYZ(obj, 0.8,0.8,0);
	let point = 0;
	let counter = 0;
	let numX = 95;
	let Alpha = 255;
	while(true)
	
	{	
		
		point = min(point, 999);
		point = max(point, 0);
		let listNum = DigitToArray(point, count);
		
		if(GetPlayerState==STATE_HIT && counter == 0)
		{
			point++;
			counter++;
		}
		if(counter>0 && counter<60){counter++;}
		if(counter>=60){counter=0;}
		
		
		
		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 595 +  iObj * 12);
			ObjRender_SetY(obj, 392);
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 320, (num + 1) * 16, 338);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 15, 18);
			ObjSpriteList2D_AddVertex(obj);
			
		}
		yield;
	}
} */

task TPlayerLife
{let alpha=255;
	//残機
	let pathDigit = GetCurrentScriptDirectory() ~ "img/life.png";
	let count = 2;

	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, GetStgFrameHeight-50);


	let obj2 = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj2, pathDigit);
	ObjRender_SetBlendType(obj2, BLEND_ALPHA);
	Obj_SetRenderPriority(obj2, 0.75);
	ObjRender_SetY(obj2, GetStgFrameHeight-30);
	
	
let point = GetPlayerLife();
	while(GetPlayerLife>=0)
	{
	if (GetCommonData("fullscreen", "false")=="true"){if (alpha>0){alpha-=5;}}
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetAlpha(obj2, alpha);
		
		point=GetPlayerLife;
		point = min(point, 7);
		point = max(point, 0);
		let listNum = DigitToArray(point, count);
		Obj_SetRenderPriority(obj, 0.75);
		ObjSpriteList2D_ClearVertexCount(obj);
		ObjSpriteList2D_ClearVertexCount(obj2);
		ascent(iObj in 0 .. 7)
		{
		ObjRender_SetX(obj, GetStgFrameWidth -120 + iObj * 16);
		if (iObj>=point){ObjSpriteList2D_SetSourceRect(obj, 0, 0, 16, 16);}
		else{ObjSpriteList2D_SetSourceRect(obj, 16, 0, 32, 16);}
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj);
		}
		ascent(i in 0..7){
			ObjRender_SetX(obj2, GetStgFrameWidth -120  + i * 16);
		if (i>=GetPlayerSpell){ObjSpriteList2D_SetSourceRect(obj2, 0, 16, 16, 32);}
		else{ObjSpriteList2D_SetSourceRect(obj2, 16, 16, 32, 32);}
		
			ObjSpriteList2D_SetDestRect(obj2, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj2);
		}
		yield;
	}
}


task THiScore()
{let alpha=255;
let Alpha=255;
	let objText = ObjText_Create();
	ObjText_SetText(objText, "HiScore");
	ObjText_SetFontSize(objText, 14);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,64, 64, 64);
	ObjText_SetFontBorderWidth(objText, 2);
	ObjText_SetFontType(objText,  "メイリオ");
	Obj_SetRenderPriority(objText, 0.99);
	ObjRender_SetX(objText, 120);
	ObjRender_SetY(objText, 11);
	ObjRender_SetScaleXYZ(objText, 0.7,0.7,0);
	
	//得点
	let pathDigit = GetCurrentScriptDirectory() ~ "img/digit.png";
	let count = 9;
let score = GetAreaCommonData("hiscore", GetCommonData("stage", "0"), 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, 110);
	ObjRender_SetScaleXYZ(obj, 0.75, 0.75, 1);

	while(true)
	{
	if (GetCommonData("fullscreen", "false")=="true"){if (alpha>0){alpha-=5;}}
		ObjRender_SetAlpha(obj, alpha);
		
		if(GetPlayerY<YAlpha)
		{
			ObjRender_SetAlpha(obj,Alpha);
			ObjRender_SetAlpha(objText,Alpha);
			if(Alpha>0){Alpha-=255/10;}
		}
		else
		{
			ObjRender_SetAlpha(obj,Alpha);
			ObjRender_SetAlpha(objText,Alpha);
			if(Alpha<255){Alpha+=255/10;}
		}
		
		if (!IsReplay){score = max(GetAreaCommonData("hiscore", GetCommonData("stage", "0"), 0), GetScore);
		score = min(score, 9999999);}
		else{score = GetAreaCommonData("hiscore", GetCommonData("stage", "0"), 0);
		score = min(score, 9999999);}
		let listNum = DigitToArray(score, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 178 + iObj * 15*0.8);
			ObjRender_SetY(obj, 15);
			ObjSpriteList2D_SetSourceRect(obj, num * 24, 0, (num + 1) * 24, 24);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 21, 21);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}

task TScore()
{let alpha=255;
let Alpha=255;
THiScore;
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Score");
	ObjText_SetFontSize(objText, 14);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,64, 64, 64);
	ObjText_SetFontBorderWidth(objText, 2);
	ObjText_SetFontType(objText,  "メイリオ");
	Obj_SetRenderPriority(objText, 0.99);
	ObjRender_SetX(objText, 357);
	ObjRender_SetY(objText, 11);
	ObjRender_SetScaleXYZ(objText, 0.7,0.7,0);
	
	//得点
	let pathDigit = GetCurrentScriptDirectory() ~ "img/digit.png";
	let count = 9;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.75);

	ObjRender_SetScaleXYZ(obj, 0.75, 0.75, 1);

	while(true)
	{if (GetCommonData("fullscreen", "false")=="true"){if (alpha>0){alpha-=5;}}
		ObjRender_SetAlpha(obj, alpha);
		
		let score = GetScore();
		score = min(score, 9999999);
		let listNum = DigitToArray(score, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		
		if(GetPlayerY<YAlpha)
		{
			ObjRender_SetAlpha(obj,Alpha);
			ObjRender_SetAlpha(objText,Alpha);
			if(Alpha>0){Alpha-=255/10;}
		}
		else
		{
			ObjRender_SetAlpha(obj,Alpha);
			ObjRender_SetAlpha(objText,Alpha);
			if(Alpha<255){Alpha+=255/10;}
		}
		
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 400 + iObj * 15*0.8);
			ObjRender_SetY(obj, 15);
			ObjSpriteList2D_SetSourceRect(obj, num * 24, 0, (num + 1) * 24, 24);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 21, 21);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}
//----------------------------------------------------
//タイマー表示
//----------------------------------------------------



//----------------------------------------------------
//スペルカード取得表示
//----------------------------------------------------
task TGainSpell(score)
{
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Spell Card Bonus!");
	ObjText_SetFontSize(objText, 32);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 128, 128, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,255, 255, 255);
	ObjText_SetFontBorderWidth(objText, 1);
	Obj_SetRenderPriority(objText, 0.6);
	ObjRender_SetX(objText, 32);
	ObjRender_SetY(objText, 98);

	let strScore = "+" ~ IntToString(score);
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, strScore);
	ObjText_SetFontSize(objScore, 32);
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 128, 128);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,255, 255, 255);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.6);
	ObjRender_SetX(objScore, 180);
	ObjRender_SetY(objScore, 140);

	loop(120)
	{
		yield;
	}
	Obj_Delete(objText);
	Obj_Delete(objScore);
}

//----------------------------------------------------
//FPS表示
//----------------------------------------------------
task TCurrentFps()
{
	let objText = ObjText_Create();
	ObjText_SetFontSize(objText, 11);
	ObjText_SetFontType(objText,  "メイリオ");
	ObjText_SetFontBold(objText, true);
	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, 1);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objText, GetScreenWidth() - 8);
	Obj_SetRenderPriority(objText, 1.0);
	ObjRender_SetX(objText, 0);
	ObjRender_SetY(objText, GetScreenHeight() - 15);

	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_SetFontType(objText,  "メイリオ");
	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;
}

