

function DrawBG_Stage3
{
	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[0]);
		SetGraphicRect(0,0,480,640);
		SetGraphicScale(3,3);
		SetGraphicAngle(-90,0,0);
		SetAlpha(230-(bg_eye_viewfrom[0]-600)/2);
		DrawGraphic3D(0,1000,-100);
	}
	
	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]/2,512+bg_vector3[0]*r,512+ry[a]+bg_vector3[1]/2);
			SetGraphicAngle(5,0,0);
			SetGraphicScale(4,4);
			SetAlpha(64);
			DrawGraphic3D(0,sy[a],-200);
			r=-r;
		}
	}
	
	SetGraphicAngle(0,0,0);
}

function BGData_Stage3
{
	bg_vector3[1]=bg_vector3[1]+6;
	bg_vector3[0]=bg_vector3[0]+1;
	stage_count++;
}



let STAGEBG_INIT=0;
let STAGEBG_DEST=1;

function Stage3_Const(let pattern)
{
	let dir=GetCurrentScriptDirectory~".\GameData\StageData\Image\";
	stage_tex=[dir~"Tex_Stage3BG_01.png",
			   dir~"Tex_Stage3BG_02.png",
	];
	
	dir=GetCurrentScriptDirectory~".\GameData\SoundData\BGM\";
	bgm=[current_bgm~"area3.wav",
		 current_bgm~"area3_boss.wav"
	];
	if(gamemode==2){bgm[1]=current_bgm~"area3_boss2.wav";}
	
				 
	alternative(pattern%2)
	case(STAGEBG_INIT){Stage_Init;}
	case(STAGEBG_DEST){Stage_Dest;}

	function Stage_Init
	{
		stagenum=3;
		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]=600;
		bg_fog_perspectiveclip[1]=2000;
		
		bg_perspectiveclip[1]=2200;
		
		bg_fogcolor[0]=32;
		bg_fogcolor[1]=32;
		bg_fogcolor[2]=96;
		
		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]);}
	}
}