

function DrawBG_Stage1
{
	WriteZBuffer(false);
	UseZBuffer(false);
	
	SetColor(128,128,128);
	local
	{
		SetTexture(stage_tex[3]);
		SetGraphicRect(0,0,768,512);
		SetGraphicScale(1.2,1.2);
		SetGraphicAngle(0,0,-90-bg_eye_viewfrom[1]);
		SetAlpha(244);
		DrawGraphic(cenX,cenY);
	}
	
	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,512,1024);
		SetGraphicAngle(180,0,0);
		SetGraphicScale(2,1);
		SetAlpha(255);
		DrawGraphic3D(0,-500,180);
	}*/
	
	let max=3;
	let tuning=GetCommonData("Memory_ConfigData");
	if(tuning[1]){max=1;}
	local
	{
		ascent(a in 0..max)
		{
			let sz=[100,120,140];
			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,2);
			SetAlpha(128);
			DrawGraphic3D(0,-500,sz[a]);
		}
	}
	
	local
	{
		ascent(a in 0..max)
		{
			let sz=[-100,-120,-140];
			let ry=[0,256,512];
			SetTexture(stage_tex[2]);
			SetGraphicRect(0,0+ry[a]+bg_vector3[1]/2,512,1024+ry[a]+bg_vector3[1]/2);
			SetGraphicAngle(5,0,0);
			SetGraphicScale(3,2);
			SetAlpha(48);
			DrawGraphic3D(0,-500,sz[a]);
		}
	}
	
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
}

function BGData_Stage1
{
	bg_vector3[1]=bg_vector3[1]-9;
	
//	if(stagepart==0)
//	{
		bg_eye_viewfrom[1]=bg_eye_viewfrom[1]+0.1*cos(stage_count/2);
//	}
	
	stage_count++;
}



let STAGEBG_INIT=0;
let STAGEBG_DEST=1;

function Stage1_Const(let pattern)
{
	let dir=GetCurrentScriptDirectory~".\GameData\StageData\Image\";
	stage_tex=[
		dir~"Tex_Stage1BG_01.png",
		dir~"Tex_Stage1BG_02.png",
		dir~"Tex_Stage1BG_03.png",
		dir~"Tex_Stage1BG_04.png"
	];
	
	dir=GetCurrentScriptDirectory~".\GameData\SoundData\BGM\";
	bgm=[current_bgm~"area1.wav",
		 current_bgm~"area1_boss.wav"];
	
				 
	alternative(pattern%2)
	case(STAGEBG_INIT){Stage_Init;}
	case(STAGEBG_DEST){Stage_Dest;}

	function Stage_Init
	{
		stagenum=1;
		stagepart=0;
		
		ascent(a in 0..length(stage_tex)){LoadGraphic(stage_tex[a]);}
		ascent(a in 0..length(bgm)){SetMusic(bgm[a],BGM_LOAD);}
		
		
		bg_vector3[0]=0;
		bg_vector3[1]=0;
		bg_vector3[2]=0;
		
		bg_eye_viewfrom[2]=90;
		bg_eye_viewfrom[1]=-90;
		bg_eye_viewfrom[0]=200;
		
		bg_fog_perspectiveclip[0]=600;
		bg_fog_perspectiveclip[1]=1400;
		
		bg_fogcolor[0]=110;
		bg_fogcolor[1]=77;
		bg_fogcolor[2]=77;
		
		stage_count=0;
	}
	
	function Stage_Dest
	{
		ascent(a in 0..length(stage_tex)){DeleteGraphic(stage_tex[a]);}
		ascent(a in 0..length(bgm)){SetMusic(bgm[a],BGM_DELETE);}
	}
}