

function DrawBG_Stage4
{
	local
	{
		SetTexture(tex[TEX_WHITE]);
		SetGraphicRect(0,0,384,448);
		SetAlpha(bg_fogcolor[0]);
		DrawGraphic(cenX,cenY);
	}
	WriteZBuffer(false);
	UseZBuffer(false);
	
	SetFog(bg_fog_perspectiveclip[0],bg_fog_perspectiveclip[1],bg_fogcolor[0],bg_fogcolor[1],bg_fogcolor[2]);
	let max=3;
	let tuning=GetCommonData("Memory_ConfigData");
	if(tuning[1]){max=2;}
	local
	{
		ascent(a in 0..max)
		{
			let sz=[100,120,140];
			let ry=[0,128,256];
			SetTexture(stage_tex[0]);
			SetGraphicRect(0,0+ry[a]+bg_vector3[1]/2,512,512+ry[a]+bg_vector3[1]/2);
			SetGraphicAngle(5,0,0);
			SetGraphicScale(3,4);
			SetAlpha(128);
			DrawGraphic3D(0,-500,sz[a]);
		}
	}
	
	local
	{
		ascent(a in 0..max)
		{
			let sz=[-100,-120,-140];
			let ry=[0,128,256];
			SetTexture(stage_tex[0]);
			SetGraphicRect(0,0+ry[a]+bg_vector3[1]/2,512,512+ry[a]+bg_vector3[1]/2);
			SetGraphicAngle(-5,0,0);
			SetGraphicScale(3,4);
			SetAlpha(128);
			DrawGraphic3D(0,-200,sz[a]);
		}
	}
	
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
}

function BGData_Stage4
{
	bg_vector3[1]=bg_vector3[1]-16;
	stage_count++;
}



let STAGEBG_INIT=0;
let STAGEBG_DEST=1;

function Stage4_Const(let pattern)
{
	let dir=GetCurrentScriptDirectory~".\GameData\StageData\Image\";
	stage_tex=[dir~"Tex_Stage4BG_01.png",
			   dir~"Tex_Stage4BG_02.png",
			   dir~"Tex_Stage4BG_03.png",
			   dir~"Tex_Stage4BG_04.png"];
	
	dir=GetCurrentScriptDirectory~".\GameData\SoundData\BGM\";
	bgm=[current_bgm~"area4.wav"
	];
	
	alternative(pattern%2)
	case(STAGEBG_INIT){Stage_Init;}
	case(STAGEBG_DEST){Stage_Dest;}

	function Stage_Init
	{
		stagenum=4;
		stagepart=0;
		
		ascent(a in 0..length(stage_tex)){LoadGraphic(stage_tex[a]);}
		ascent(a in 0..length(bgm)){LoadMusic(bgm[a]);}
		
		
		bg_vector3[0]=0;
		bg_vector3[1]=0;
		bg_vector3[2]=0;
		
		bg_eye_viewfrom[2]=90;
		bg_eye_viewfrom[1]=-45;
		bg_eye_viewfrom[0]=200;
		
		bg_fog_perspectiveclip[0]=300;
		bg_fog_perspectiveclip[1]=1500;
		
		bg_fogcolor[0]=16;
		bg_fogcolor[1]=16;
		bg_fogcolor[2]=16;
		
		stage_count=0;
	}
	
	function Stage_Dest
	{
		ascent(a in 0..length(stage_tex)){DeleteGraphic(stage_tex[a]);}
		ascent(a in 0..length(bgm)){DeleteMusic(bgm[a]);}
	}
}