

function DrawBG_Stage2
{
	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,1024);
		SetGraphicScale(2,2);
		SetGraphicAngle(-90,0,0);
		SetAlpha(244);
		DrawGraphic3D(0,1000,-400);
	}
	
	let max=3;
	let tuning=GetCommonData("Memory_ConfigData");
	if(tuning[1]){max=1;}
	local
	{
		ascent(a in 0..max)
		{
			let sy=[180,200,220];
			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(4,4);
			SetAlpha(64);
			DrawGraphic3D(0,sy[a],-1200);
		}
	}
	
	local
	{
		ascent(a in 0..max)
		{
			let sy=[180,200,220];
			let ry=[0,128,256];
			SetTexture(stage_tex[1]);
			SetGraphicRect(0,0+ry[a]+bg_vector3[1]/2,512,512+ry[a]+bg_vector3[1]/2);
			SetGraphicAngle(5,0,0);
			SetGraphicScale(4,4);
			SetAlpha(32);
			DrawGraphic3D(0,sy[a],-200);
		}
	}
	
	SetGraphicAngle(0,0,0);
}

function BGData_Stage2
{
	bg_vector3[1]=bg_vector3[1]+9;
	stage_count++;
}



let STAGEBG_INIT=0;
let STAGEBG_DEST=1;

function Stage2_Const(let pattern)
{
	let dir=GetCurrentScriptDirectory~".\GameData\StageData\Image\";
	stage_tex=[
		dir~"Tex_Stage2BG_01.png",
		dir~"Tex_Stage2BG_02.png",
		dir~"Tex_Stage2BG_03.png",
		dir~"Tex_Stage2BG_04.png"
	
	];
	
	dir=GetCurrentScriptDirectory~".\GameData\SoundData\BGM\";
	bgm=[current_bgm~"area2.wav",
		 current_bgm~"area2_boss.wav"];
	
				 
	alternative(pattern%2)
	case(STAGEBG_INIT){Stage_Init;}
	case(STAGEBG_DEST){Stage_Dest;}

	function Stage_Init
	{
		stagenum=2;
		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_lookat[0]=0;
		bg_eye_lookat[1]=0;
		bg_eye_lookat[2]=0;
		
		bg_eye_viewfrom[2]=-40;
		bg_eye_viewfrom[1]=90;
		bg_eye_viewfrom[0]=500;
		
		bg_fog_perspectiveclip[0]=200;
		bg_fog_perspectiveclip[1]=1500;
		
		bg_perspectiveclip[1]=2000;
		
		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]);}
	}
}