

function DrawBG_Stage5
{
	WriteZBuffer(false);
	UseZBuffer(false);
	SetFog(bg_fog_perspectiveclip[0],bg_fog_perspectiveclip[1],bg_fogcolor[0],bg_fogcolor[1],bg_fogcolor[2]);
	local
	{
		SetTexture(stage_tex[2]);
		SetGraphicRect(0,0,768,768);
		SetGraphicScale(1.5,1.5);
		SetGraphicAngle(-70,0,-stage_count/4);
//		SetAlpha(255);
		SetAlpha(230-(bg_eye_viewfrom[0]-600)/2);
		DrawGraphic3D(0,700,250);
	}
	
	local
	{
		SetTexture(stage_tex[3]);
		SetGraphicRect(0,0,512,512);
		SetGraphicScale(1,1);
		SetGraphicAngle(-90,0,stage_count/4);
//		SetAlpha(255);
		SetAlpha(230-(bg_eye_viewfrom[0]-600)/2);
		DrawGraphic3D(0,400,250);
	}
	
	local
	{
		SetTexture(stage_tex[0]);
		SetGraphicRect(0,0+bg_vector3[1],640,640+bg_vector3[1]);
		SetGraphicAngle(5,0,0);
		SetGraphicScale(3,4);
		SetAlpha(240);
		DrawGraphic3D(0,600,-200);
	}
	
	let max=4;
	let tuning=GetCommonData("Memory_ConfigData");
	if(tuning[1]){max=2;}
	local
	{
		let r=1;
		ascent(a in 0..max)
		{
			let sy=[180,200,220,240];
			let ry=[0,128,256,384];
			SetTexture(stage_tex[1]);
			SetGraphicRect(0+bg_vector3[0]*r,0+ry[a]+bg_vector3[1],512+bg_vector3[0]*r,512+ry[a]+bg_vector3[1]);
			SetGraphicAngle(5,0,0);
			SetGraphicScale(4,4);
			SetAlpha(48);
			DrawGraphic3D(0,sy[a],-200);
			r=-r;
		}
	}
	

	
	SetGraphicAngle(0,0,0);
}

function BGData_Stage5
{
	bg_vector3[1]=bg_vector3[1]+1;
	bg_vector3[0]=bg_vector3[0]+0.25;
	stage_count++;
}



let STAGEBG_INIT=0;
let STAGEBG_DEST=1;

function Stage5_Const(let pattern)
{
	let dir=GetCurrentScriptDirectory~".\GameData\StageData\Image\";
	stage_tex=[dir~"Tex_Stage5BG_01.png",
			   dir~"Tex_Stage5BG_02.png",
			   dir~"Tex_Stage5BG_03.png",
			   dir~"Tex_Stage5BG_04.png"];
	
	dir=GetCurrentScriptDirectory~".\GameData\SoundData\BGM\";
	bgm=[current_bgm~"area5.wav",
		 current_bgm~"area5_boss.wav"
	];
	if(gamemode==2){bgm[1]=current_bgm~"area5_boss2.wav";}
				 
	alternative(pattern%2)
	case(STAGEBG_INIT){Stage_Init;}
	case(STAGEBG_DEST){Stage_Dest;}

	function Stage_Init
	{
		stagenum=5;
		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]=-10;
		bg_eye_viewfrom[1]=90;
		bg_eye_viewfrom[0]=1000;
		
		bg_fog_perspectiveclip[0]=500;
		bg_fog_perspectiveclip[1]=1500;
		
		bg_fogcolor[0]=0;
		bg_fogcolor[1]=0;
		bg_fogcolor[2]=0;
		
		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]);}
	}
}