task BombExtend//ボムエクステンド
{
	BombOverExtend;
	let BombExtendNum=0;
	let BombExtendCounter=0;
	let Necessary=0;
	alternative(GetCommonDataDefault("AutoBombMode",0))
	case(0){Necessary=5000;}
	case(0.5){Necessary=10000;}
	case(1){Necessary=20000;}
	loop
	{
		BombExtendCounter=MagicFragment-(Necessary*BombExtendNum);
		if(BombExtendCounter>=Necessary)
		{
			BombExtendCounter-=Necessary;
			BombExtendNum+=1;
			BombExtendTask;
		}
		yield;
	}

	task BombExtendTask
	{
		if((OnMissed))
		{
			while(OnMissed){yield;}
			wait(15);
		}
		
		PlaySE(SE[4]);
		Ah_Sub_EscapeDeathCheck;
		Ah_DoubleExtendCheck;
		AddBomb(4);

	}

	task BombExtendEffect
	{
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgLight);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetRenderState(obj, ADD);
	ObjEffect_CreateVertex(obj, 4);

	ObjEffect_SetVertexXY(obj, 0, -32, -32);
	ObjEffect_SetVertexXY(obj, 1,32, -32);
	ObjEffect_SetVertexXY(obj, 2, 32, 32);
	ObjEffect_SetVertexXY(obj, 3, -32, 32);
		
	ObjEffect_SetVertexUV(obj, 0,  0,  0);
	ObjEffect_SetVertexUV(obj, 1,  64, 0);
	ObjEffect_SetVertexUV(obj, 2, 64, 64);
	ObjEffect_SetVertexUV(obj, 3, 0,  64);

	let Alpha=255;
	let R=50;let G=255;let B=50;
	ascent(let i in 0..4)
	{
		ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
	}

	let x=GetClipMaxX+96+8+(GetPlayerBomb-1)*16;
	Obj_SetPosition(obj,x,195);

	ObjEffect_SetLayer(obj,8);

	let Zangle=rand(0,360);
	ObjEffect_SetAngle(obj,0,0,Zangle);

	let Scale=0.0;
	SetCommonData("OnBombExtend",true);
	loop(30)
	{
		ObjEffect_SetScale(obj, Scale, Scale);
		ObjEffect_SetAngle(obj,0,0,Zangle);
		Zangle+=6;
		Scale+=0.5/30;
		yield;
	}
	SetCommonData("OnBombExtend",false);
	loop(30)
	{
		ObjEffect_SetScale(obj, Scale, Scale);
		ObjEffect_SetAngle(obj,0,0,Zangle);
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		Zangle+=6;
		Scale+=0.5/30;
		Alpha-=255/30;
		yield;
	}
	Obj_Delete(obj);
	}
}
task BombOverExtend
{
loop
{
	if(GetPlayerBomb>=9)
	{
		AddBomb(-1);
		if(BurstMode==0)
		{
		Power=1000;
		}
		MagicCounter=10000;
		SetPlayerInvincibility(240);
		BulletErase(180);
		AddScore(50000000);
		Ah_Sub_OverExtendCheck;
	}
yield;
}
}

task BurstRankAndRushGaugeDraw
{
let RankNum=0;
let RankCounter=0;
let RushAlpha=50;
let RushAlphaC1=180;
let RushAlphaC2=75;
let RushAlphaAngle=0;
wait(5);
while(GetCommonDataDefault("TitleMenu",false)){yield;}
if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="None"){return;}
let RX=35;
let RY=75;
let BRnum=[0,0];
loop
{
RankBerDisplay(RX+71,RY);
RankDisplay(RX,RY,RushAlpha);

BRnum[0]=trunc(BurstRank%10000/1000);
BRnum[1]=trunc(BurstRank/10000);

if(GetCommonDataDefault("BurstStop",false)==false)
{//走行点
	AddScore((BRnum[1]*10+BRnum[0])*1000);
}

Ranknum(RX+86,RY-5,BRnum[0]);

if(BurstRank>=10000)
{
	Ranknum(RX+86-1*10,RY-5,BRnum[1]);
}

if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="Extream")
{
	RushBerDisplay(RX+71,RY+15);
	RushDisplay(RX,RY+15,RushAlpha);
	PNSignDisplay(RY+8);
}
if(IsBossExisting || GetCommonDataDefault("IsMSDBossExisting",false))
{
	if(RY<GetClipMinY+80)
	{
	RY+=0.5;
	}
}
else
{
	if(RY>GetClipMinY+60)
	{
	RY-=0.5;
	}
}
RushAlpha=RushAlphaC1+RushAlphaC2*cos(RushAlphaAngle);
RushAlphaAngle+=6;
yield;
}

task PNSignDisplay(y)//ライフバーの枠の設定
{
	//let BossLifeMax=GetEnemyLife;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -7, -7);
		ObjEffect_SetVertexXY(obj, 1, 7,  -7);
		ObjEffect_SetVertexXY(obj, 2, 7, 7);
		ObjEffect_SetVertexXY(obj, 3,  -7,  7);
		
		ObjEffect_SetVertexUV(obj, 0,  7,  41);
		ObjEffect_SetVertexUV(obj, 1, 21, 41);
		ObjEffect_SetVertexUV(obj, 2, 21,  54);
		ObjEffect_SetVertexUV(obj, 3, 7, 54);
		ObjEffect_SetLayer(obj,3);
		ObjEffect_SetScale(obj, 0.4,0.6);


		let x=70+35.0*PNRate/100;
		Obj_SetPosition(obj,x,y);
/*
		let Alpha=50;
		if((GetPlayerY>GetClipMinY+150) && OnMissed)
		{
			Alpha=255;
		}
		if((GetPlayerY<GetClipMinY+150))
		{
			Alpha=255+300*(GetPlayerY-(GetClipMinY+150))/(GetClipMinY+150);
		}
		if(Alpha<50){Alpha=50;}
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj, i, Alpha, 255, 255, 255);
			}
*/
			yield;
		Obj_Delete(obj);
}


task RankBerDisplay(x,y)//ライフバーの枠の設定
{
	//let BossLifeMax=GetEnemyLife;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -71, -5);
		ObjEffect_SetVertexXY(obj, 1, 0,  -5);
		ObjEffect_SetVertexXY(obj, 2, 0, 5);
		ObjEffect_SetVertexXY(obj, 3,  -71,  5);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  11);
		ObjEffect_SetVertexUV(obj, 1,  148, 11);
		ObjEffect_SetVertexUV(obj, 2, 148,  21);
		ObjEffect_SetVertexUV(obj, 3, 6, 21);
		ObjEffect_SetLayer(obj,3);
		ObjEffect_SetScale(obj, 1,0.6);



		Obj_SetPosition(obj,x,y);

		let Alpha=50;
		if((GetPlayerY>GetClipMinY+150))
		{
			Alpha=255;
		}
		if((GetPlayerY<GetClipMinY+150))
		{
			Alpha=255+300*(GetPlayerY-(GetClipMinY+150))/(GetClipMinY+150);
		}
		if(Alpha<50){Alpha=50;}
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj, i, Alpha, 255, 255, 255);
			}

			yield;
		Obj_Delete(obj);
}

task RankDisplay(x,y,Alpha)//ライフバーのバー部分の設定
{
		let scale=2.5;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, 0, -3);
		ObjEffect_SetVertexXY(obj, 1, 71,  -3);
		ObjEffect_SetVertexXY(obj, 2, 71, 3);
		ObjEffect_SetVertexXY(obj, 3,  0,  3);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  148, 27);
		ObjEffect_SetVertexUV(obj, 2, 148,  33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);
		ObjEffect_SetLayer(obj,3);

		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,150,255,255,255);
		}

		Obj_SetPosition(obj,x,y);

		if((GetPlayerY>GetClipMinY+150))
		{
			Alpha*=255/255;
		}
		if((GetPlayerY<GetClipMinY+150))
		{
			Alpha*=(255+300*(GetPlayerY-(GetClipMinY+150))/(GetClipMinY+150))/255;
		}

		if(Alpha<50){Alpha=50;}
			RankCounter=BurstRank%1000;
			if(BurstRank>=10000){RankCounter=999;}

			scale=RankCounter/1000;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255*(BurstRank/10000),0,255-255*(BurstRank/10000));
			}
			ObjEffect_SetScale(obj, scale,0.6);
			yield;
		Obj_Delete(obj);
}

task Ranknum(x,y,num)
{
		let scx=0.4;
		let scy=0.4;
		let obj0 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj0,imgNumber);
		ObjEffect_SetPrimitiveType(obj0, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj0, ADD); 
		ObjEffect_CreateVertex(obj0, 4);
		ObjEffect_SetVertexXY(obj0, 0, -13, -16);
		ObjEffect_SetVertexXY(obj0, 1, 13,  -16);
		ObjEffect_SetVertexXY(obj0, 2, 13, 16);
		ObjEffect_SetVertexXY(obj0, 3,  -13,  16);
		
		ObjEffect_SetVertexUV(obj0, 0,  0+40*num,  6);
		ObjEffect_SetVertexUV(obj0, 1,  26+40*num, 6);
		ObjEffect_SetVertexUV(obj0, 2, 26+40*num,  38);
		ObjEffect_SetVertexUV(obj0, 3, 0+40*num, 38);

		let Alpha=255;
		if((GetPlayerY>GetClipMinY+150))
		{
			Alpha=255;
		}
		if((GetPlayerY<GetClipMinY+150))
		{
			Alpha=255+300*(GetPlayerY-(GetClipMinY+150))/(GetClipMinY+150);
		}
		if(Alpha<50){Alpha=50;}

		let R=255;let G=255;let B=255;

		ObjEffect_SetVertexColor(obj0,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj0,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj0,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj0,3,Alpha,R,G,B);
		
		ObjEffect_SetScale(obj0, scx,scy);
		Obj_SetPosition(obj0,x,y+5);
		ObjEffect_SetLayer(obj0,3);
		yield;
		Obj_Delete(obj0);
}

task RushBerDisplay(x,y)//ライフバーの枠の設定
{
	//let BossLifeMax=GetEnemyLife;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -71, -5);
		ObjEffect_SetVertexXY(obj, 1, 0,  -5);
		ObjEffect_SetVertexXY(obj, 2, 0, 5);
		ObjEffect_SetVertexXY(obj, 3,  -71,  5);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  11);
		ObjEffect_SetVertexUV(obj, 1,  148, 11);
		ObjEffect_SetVertexUV(obj, 2, 148,  21);
		ObjEffect_SetVertexUV(obj, 3, 6, 21);
		ObjEffect_SetLayer(obj,3);
		ObjEffect_SetScale(obj, 1,0.6);
		Obj_SetPosition(obj,x,y);

		let Alpha=50;
		if((GetPlayerY>GetClipMinY+150))
		{
			Alpha=255;
		}
		if((GetPlayerY<GetClipMinY+150))
		{
			Alpha=255+300*(GetPlayerY-(GetClipMinY+150))/(GetClipMinY+150);
		}
		if(Alpha<50){Alpha=50;}
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj, i, Alpha, 255, 255, 255);
			}

			yield;
		Obj_Delete(obj);
}

task RushDisplay(x,y,Alpha)//ライフバーのバー部分の設定
{x+=35;
		let scale=2.5;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, 0, -3);
		ObjEffect_SetVertexXY(obj, 1, 71,  -3);
		ObjEffect_SetVertexXY(obj, 2, 71, 3);
		ObjEffect_SetVertexXY(obj, 3,  0,  3);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  148, 27);
		ObjEffect_SetVertexUV(obj, 2, 148,  33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);
		ObjEffect_SetLayer(obj,3);

		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,150,255,255,255);
		}

		if(RushGauge==1000)
		{
			x-=71/2-1;
		}
		else if(RushGauge==-1000)
		{
			x+=71/2;
		}

		Obj_SetPosition(obj,x,y);
/*
		let Alpha=50;
		if((GetPlayerY>GetClipMinY+150))
		{
			Alpha=255;
		}
		if((GetPlayerY<GetClipMinY+150))
		{
			Alpha=255+300*(GetPlayerY-(GetClipMinY+150))/(GetClipMinY+150);
		}
*/
		if((GetPlayerY>GetClipMinY+150))
		{
			Alpha*=255/255;
		}
		if((GetPlayerY<GetClipMinY+150))
		{
			Alpha*=(255+300*(GetPlayerY-(GetClipMinY+150))/(GetClipMinY+150))/255;
		}

		if(Alpha<50){Alpha=50;}

			scale=RushGauge/1000;
			if(absolute(RushGauge)==1000)
			{
				scale*=2;
			}
			ascent(let i in 0..4)
			{
				if(RushGauge>=0)
				{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,0,0);
				}
				else
				{
				ObjEffect_SetVertexColor(obj,i,Alpha,0,255,0);
				}
			}
			ObjEffect_SetScale(obj, scale/2,0.6);
			yield;
		Obj_Delete(obj);
}

}