
function Result
{
	let resultflg=1;
	WhiteOut;
	wait(50);
	ResultState;
	SetBonus;
	itemrate_num=1;
	
	resultflg=0;
	itempoint_totalcount=0;
	itemmulti_totalcount=0;
	
	function SetBonus
	{
		let CLEAR=0;
		let BASE=1;
		let LIFELINE=2;
		let RATE=3;
		let POINTCOUNT=4;
		let RATECOUNT=5;
		let TOTAL=6;
		let PUSHKEY=7;
		local
		{
			let point=itempoint_totalcount;
			let multi=floor(itemmulti_totalcount);
			ObjectText(POINTCOUNT,minX+32,minY+32);
			Set(point,cenX,minY+32);
			
			
			ObjectText(RATECOUNT,minX+32,minY+48);
			Set(multi,cenX,minY+48);
			
			let brate=point*multi;
			ObjectText(RATE,minX+32,minY+92);
			Set(brate,cenX,minY+96);
			
			score=GetCommonData("Score");
			local
			{
				ObjectText(CLEAR,minX+32,minY+130);
				Set(stagenum,minX+32,minY+150);
				Number(10,minX+48,minY+150);
				Set(brate,minX+64,minY+150);
				let c=floor(log10(brate))+1;
				Number(10,minX+64+14*c,minY+150);
				Set(brate,minX+64+14*c+24,minY+150);
				
				Set(stagenum*brate*brate,minX+32,minY+170);
				
				score+=(stagenum*brate*brate);
			}
			
			local
			{
				ObjectText(BASE,minX+32,minY+210);
				
				let point=floor(itempoint/10);
				Set(point,minX+32,minY+230);
				let c=floor(log10(point))+1;
				Number(10,minX+32+14*c,minY+230);
				
				Set(multi,minX+32+14*c+24,minY+230);
				c+=floor(log10(itemmulti_totalcount))+1;
				Number(10,minX+32+14*c+24,minY+230);
				Set(brate,minX+32+14*c+48,minY+230);
				
				Set(point*brate*multi,minX+32,minY+250);
				
				score+=(point*brate*multi);
			}
			
			local
			{
				ObjectText(LIFELINE,minX+32,minY+290);
				let base=(GetPlayerLife*2+GetPlayerBomb)*111;
				Set(base,minX+32,minY+310);
				let c=floor(log10(base))+1;
				Number(10,minX+32+14*c,minY+310);
				Set(point,minX+32+14*c+24,minY+310);
				c+=floor(log10(itempoint_totalcount))+1;
				Number(10,minX+32+14*c+24,minY+310);
				Set(brate,minX+32+14*c+48,minY+310);
				c+=floor(log10(brate))+1;
				Number(10,minX+32+14*c+48,minY+310);
				Set(stagenum,minX+32+14*c+72,minY+310);
				
				Set(base*point*brate*stagenum,minX+32,minY+330);
				
				score+=(base*point*brate*stagenum);
			}
			
			local
			{
				ObjectText(TOTAL,minX+32,minY+390);
				Set(score,minX+32,minY+410);
			}
			
			ObjectText(PUSHKEY,cenX+24,minY+430);
			SetCommonData("Score",score);
		}
		
		task Set(let num,let sx,let sy)
		{
			let lp=floor(log10(num))+1;
			let i=lp;
			loop(lp)
			{
				let leng=16;
				let posx=sx+(lp-i)*(leng/1.4);
				let posy=sy;
				let rc=(num%(10^i)-num%(10^(i-1)))/(10^(i-1));
				
				Number(rc,posx,posy);
				if((i)%4==1&&i>1)
				{
					Number(11,posx,posy);
				}
				i--;
			}
			if(num==0)
			{
				Number(0,sx,sy);
			}
		}
		
		task ObjectText(let type,let sx,let sy)
		{
			let rect=[];
			alternative(type)
			case(CLEAR){rect=[0,0,192,32];}
			case(BASE){rect=[0,32,192,64];}
			case(LIFELINE){rect=[0,64,192,96];}
			case(RATE){rect=[0,128,128,160];}
			case(POINTCOUNT){rect=[0,160,160,176];}
			case(RATECOUNT){rect=[0,176,160,192];}
			case(TOTAL){rect=[0,96,128,128];}
			case(PUSHKEY){rect=[0,192,160,224];}
			let obj=SetEffectObject(tex[TEX_RESULT],7);
			ObjEffect_SetRenderState(obj,ALPHA);
			SetEffectObjectRect(obj,rect[0],rect[1],rect[2],rect[3]);
			Obj_SetPosition(obj,sx+(rect[2]-rect[0])/2,sy);
			let alpha=255;
			let count=0;
			while(!Obj_BeDeleted(obj))
			{
				if(type==PUSHKEY)
				{
					alpha=127+120*cos(count*3);
					count++;
				}
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);
				}
				if(!resultflg){Obj_Delete(obj);}
				yield;
			}
		}
		task Number(let num,let x,let y)
		{
			let obj=SetEffectObject(tex[TEX_RESULT],7);
			ObjEffect_SetRenderState(obj,ALPHA);
			SetEffectObjectRect(obj,0+16*num,240,16+16*num,256);
			Obj_SetPosition(obj,x,y);
			while(!Obj_BeDeleted(obj))
			{
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,255,255,255,255);
				}
				if(!resultflg){Obj_Delete(obj);}
				yield;
			}
		}
		loop
		{
			if(GetKeyState(VK_SHOT)==KEY_PUSH)
			{
				break;
			}
			yield;
		}
	}
	task ResultState
	{
		while(resultflg)
		{
			ForbidShot(true);
			ForbidBomb(true);
			SetPlayerX(cenX);
			SetPlayerY(380);
			yield;
		}
		ForbidShot(false);
		ForbidBomb(false);
	}
	task WhiteOut
	{
		loop(8)
		{
			WhiteOut;
			wait(2);
		}
		task WhiteOut
		{
			let obj=SetEffectObject(tex[TEX_WHITE],7);
			SetEffectObjectRect(obj,0,0,320,240);
			ObjEffect_SetRenderState(obj,ADD);
			Obj_SetPosition(obj,cenX,cenY);
			
			let count=0;
			let scale=1;
			let alpha=16;
			while(alpha>2)
			{
				ObjEffect_SetScale(obj,scale,scale);
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);
				}
				if(!resultflg){alpha-=5;}
				else if(alpha<250){alpha+=2;}
				scale+=0.2;
				count++;
				yield;
			}
			Obj_Delete(obj);
		}
	}
}