#e[Stage]
#Title[K[_̗U]
#Text[GXvK[_+vMA̗
[U[`L[Ŋo]
#BGM[]
#Player[.\K[_̗p@\atype.txt , .\K[_̗p@\btype.txt]
#ScriptVersion[2]

script_stage_main{
	SetCommonData("kinkai",0);
	SetCommonData("bgx",0);
	SetCommonData("bgy",0);
	SetCommonData("haya",1);
	SetCommonData("ransu",0);
	SetCommonData("kinkaiten",0);
	SetCommonData("kakusei",0);
	SetCommonData("zessi",0);
	SetCommonData("ruikei",0);
	SetCommonData("gekitui",0);
	SetCommonData("kakuseikinsi",false);
	SetCommonData("autobomb",true);
	SetCommonData("score",0);

	SetCommonData("ex",0);

	let extend = 1;
	let stage = 1;
	
	let phase = 0;
	let speed = 1;
	let fspeedup = false;
	let haya = false;
	let time = 0;
	let clear = false;
	let misscount = 0;
	let clearhyouzi = 0;
	let select = 0;
	let stageselect = false;
	let haikei = true;

	let zakotank1 = GetCurrentScriptDirectory~"zakotank1.txt";
	let zakotank2 = GetCurrentScriptDirectory~"zakotank2.txt";
	let tank1 = GetCurrentScriptDirectory~"tank1.txt";
	let tank2 = GetCurrentScriptDirectory~"tank2.txt";
	let tankbig1 = GetCurrentScriptDirectory~"tankbig1.txt";

	let zakohune1 = GetCurrentScriptDirectory~"zakohune1.txt";
	let zakocannon1 = GetCurrentScriptDirectory~"zakocannon1.txt";
	let zakocannon2 = GetCurrentScriptDirectory~"zakocannon2.txt";
	let zakocannon3 = GetCurrentScriptDirectory~"zakocannon3.txt";
	let cannonbig1 = GetCurrentScriptDirectory~"cannonbig1.txt";

	let clone1 = GetCurrentScriptDirectory~"clone1.txt";
	let clone2 = GetCurrentScriptDirectory~"clone2.txt";
	let clone3 = GetCurrentScriptDirectory~"clone3.txt";
	
	let zakoheli1 = GetCurrentScriptDirectory~"zakoheli1.txt";
	let zakoheli2 = GetCurrentScriptDirectory~"zakoheli2.txt";
	let zakoheli3 = GetCurrentScriptDirectory~"zakoheli3.txt";
	let zakoair1 = GetCurrentScriptDirectory~"zakoair1.txt";
	let zakoair2 = GetCurrentScriptDirectory~"zakoair2.txt";
	let air1 = GetCurrentScriptDirectory~"air1.txt";
	let air2 = GetCurrentScriptDirectory~"air2.txt";
	let air3 = GetCurrentScriptDirectory~"air3.txt";
	let air4 = GetCurrentScriptDirectory~"air4.txt";
	let air5 = GetCurrentScriptDirectory~"air5.txt";
	let airbig1 = GetCurrentScriptDirectory~"airbig1.txt";
	let airbig2 = GetCurrentScriptDirectory~"airbig2.txt";
	
	let senkan1 = GetCurrentScriptDirectory~"senkan1.txt";
	let senkan2 = GetCurrentScriptDirectory~"senkan2.txt";
	let senkan3 = GetCurrentScriptDirectory~"senkan3.txt";

	let lift = GetCurrentScriptDirectory~"lift.txt";
	let hunebig1 = GetCurrentScriptDirectory~"hunebig1.txt";

	let item = GetCurrentScriptDirectory~"item.txt";
	let izumi = GetCurrentScriptDirectory~"izumi.txt";
	let obj1 = GetCurrentScriptDirectory~"obj1.txt";
	let obj2 = GetCurrentScriptDirectory~"obj2.txt";
	let train = GetCurrentScriptDirectory~"train.txt";

	let st1semiboss = GetCurrentScriptDirectory~"st1semiboss.txt";
	let st1boss = GetCurrentScriptDirectory~"st1boss.txt";
	let st2semiboss = GetCurrentScriptDirectory~"st2semiboss.txt";
	let st2boss = GetCurrentScriptDirectory~"st2boss.txt";
	let st3semiboss = GetCurrentScriptDirectory~"st3semiboss.txt";
	let st3boss = GetCurrentScriptDirectory~"st3boss.txt";
	let st4semiboss = GetCurrentScriptDirectory~"st4semiboss.txt";
	let st4boss = GetCurrentScriptDirectory~"st4boss.txt";
	let st5semiboss1 = GetCurrentScriptDirectory~"st5semiboss1.txt";
	let st5semiboss2 = GetCurrentScriptDirectory~"st5semiboss2.txt";
	let st5semiboss3 = GetCurrentScriptDirectory~"st5semiboss3.txt";
	let st5semiboss4 = GetCurrentScriptDirectory~"st5semiboss4.txt";
	let st5boss1 = GetCurrentScriptDirectory~"st5boss1.txt";

	let bgmst1 = GetCurrentScriptDirectory~"bgm\Stage1.mp3";
	let bgmst2 = GetCurrentScriptDirectory~"bgm\Stage2.mp3";
	let bgmst3 = GetCurrentScriptDirectory~"bgm\Stage3.mp3";
	let bgmst4 = GetCurrentScriptDirectory~"bgm\Stage4.mp3";
	let bgmst5 = GetCurrentScriptDirectory~"bgm\Stage5.mp3";
	let bgmboss = GetCurrentScriptDirectory~"bgm\Boss.mp3";
	let bgmlastboss = GetCurrentScriptDirectory~"bgm\LastBoss.mp3";
	let bgmtruelastboss = GetCurrentScriptDirectory~"bgm\TrueLastBoss.mp3";
	let bgmclear = GetCurrentScriptDirectory~"bgm\Clear.mp3";

	let se4 = GetCurrentScriptDirectory~"wav\se4.wav";

	let system = GetCurrentScriptDirectory~"img\system.png";
	let number = GetCurrentScriptDirectory~"img\number.png";
	let stringarray=["0","1","2","3","4","5","6","7","8","9"];
	@Initialize(){
		SetDefaultStatusVisible(false);
		/*
		if(GetKeyState(VK_USER)==KEY_HOLD){
			SetCommonData("ex",1);
		}
		*/
		SetRateScoreSystemEnable(false);
		LoadGraphic( system );
		LoadGraphic( number );
		LoadGraphic( GetCurrentScriptDirectory~"img\title.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st1bg1.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st1bg2.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st2bg1.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st3bg1.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st3bg2.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st4bg1.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st4bg2.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st4bg3.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st4bg4.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st5bg1.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st5bg2.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st5bg3.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st5bg4.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st5bg5.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st5bg6.png" );
		LoadGraphic( GetCurrentScriptDirectory~"img\st5bg7.png" );
		AddPoint(100);
		SetCommonData("bairitu",1);
		ExpertEx( false, 3, 3 );
	}
	@MainLoop(){
		if(stage==0){
			ForbidBomb(true);
			ForbidShot(true);
			SetPlayerX(224);
			SetPlayerY(400);
			if(GetKeyState(VK_DOWN)==KEY_PUSH){
				select+=1;
				if(select>3){select=0}
			}
			if(GetKeyState(VK_UP)==KEY_PUSH){
				select-=1;
				if(select<0){select=3}
			}
			if(GetKeyState(VK_USER)==KEY_PUSH){
				if(GetCommonData("ex")==0){SetCommonData("ex",1);}
				else if(GetCommonData("ex")==1){SetCommonData("ex",0);}
			}
			if(GetKeyState(VK_BOMB)==KEY_PUSH){
				if(GetCommonData("autobomb")==false){SetCommonData("autobomb",true);}
				else if(GetCommonData("autobomb")==true){SetCommonData("autobomb",false);}
			}
			if(GetKeyState(VK_SHOT)==KEY_PUSH){
				SetCommonData("kakuseikinsi",false);
				ForbidBomb(false);
				ForbidShot(false);
				if(select==0){stage=1}
				else{stageselect=true;stage=select;ExtendPlayer(6);}
			}
		}
		if(stage==1){Stage1;}
		if(stage==2){Stage2;}
		if(stage==3){Stage3;}
		if(stage==4){Stage4;}
		if(stage==5){Stage5;}


		time++;

		if(OnPlayerMissed==true){DeleteEnemyShotImmediatelyInCircle(ALL,224,248,500);}

		if(GetCommonData("kakusei")==0){SetCommonData("kinkaiten",0);SetCommonData("kinkai",0);}

		if(GetCommonData("score")>=200000000*(extend*(extend + 1))
			&&clear==false&&stageselect==false){
			ExtendPlayer(1);
			PlaySE("se1UP.wav");
			extend++;
		}
		if(GetMissCount>misscount){
			SetCommonData("ruikei",trunc(GetCommonData("ruikei")*0.75));
			misscount++;
		}

		if(GetCommonData("kinkaiten")>0){
			SetCommonData("kinkaiten",GetCommonData("kinkaiten")-1);
		}
		if(GetCommonData("gekitui")==1&&GetTimeOfPlayerInvincibility==0){ShootDownPlayer;}
		SetCommonData("gekitui",0);
		yield;
	}
	@Finalize(){
		AddScore(-GetScore+GetCommonData("score")/100);
	}
	@BackGround{
		if(GetCommonData("zessi")==0){SetColor(255, 255, 255);}
		else{SetColor(255, 155, 155);}

		if(haikei==true){
			if(stage==1){
				if(phase<=1){
					if(time<=3300){
						SetTexture( GetCurrentScriptDirectory~"img\st1bg1.png" );
						SetGraphicRect(GetCommonData("bgx"),2820-GetCommonData("bgy"),GetCommonData("bgx")+384,2820-GetCommonData("bgy")+448);
						DrawGraphic(224,240);
					}
					else if(time>3300){
						SetTexture( GetCurrentScriptDirectory~"img\st1bg2.png" );
						SetGraphicRect(GetCommonData("bgx"),2405+2800-GetCommonData("bgy"),GetCommonData("bgx")+384,2405+2800-GetCommonData("bgy")+480);
						DrawGraphic(224,240);
					}
				}
			}
			else if(stage==2){
				SetTexture( GetCurrentScriptDirectory~"img\st2bg1.png" );
				SetGraphicRect(GetCommonData("bgx"),3240-GetCommonData("bgy"),GetCommonData("bgx")+384,3240-GetCommonData("bgy")+448);
				DrawGraphic(224,240);
			}
			else if(stage==3){
				if(phase<=1){
					SetTexture( GetCurrentScriptDirectory~"img\st3bg1.png" );
					SetGraphicRect(GetCommonData("bgx"),-time*4,GetCommonData("bgx")+384,-time*4+448);
					DrawGraphic(224,240);
				}
				else if(phase==2){
					SetTexture( GetCurrentScriptDirectory~"img\st3bg2.png" );
					SetGraphicRect(GetCommonData("bgx"),2820-GetCommonData("bgy"),GetCommonData("bgx")+384,2820-GetCommonData("bgy")+448);
					DrawGraphic(224,240);
				}
			}
			else if(stage==4){
				if(phase>=0){
					if(phase<=1||time<3000){
						SetTexture( GetCurrentScriptDirectory~"img\st4bg3.png" );
						SetGraphicRect(GetCommonData("bgx")*3,-GetCommonData("bgy")*3,GetCommonData("bgx")*3+384,-GetCommonData("bgy")*3+448);
					}
					DrawGraphic(224,240);
					if(time<=300&&phase<=1){
						SetTexture( GetCurrentScriptDirectory~"img\st4bg1.png" );
						SetGraphicRect(GetCommonData("bgx"),1620-time*4,GetCommonData("bgx")+384,1620-time*4+448);
						DrawGraphic(224,240);
					}
					if(phase>=2&&time>2200){
						SetTexture( GetCurrentScriptDirectory~"img\st4bg4.png" );
						SetGraphicRect(GetCommonData("bgx"),1620+3970-GetCommonData("bgy"),GetCommonData("bgx")+384,1620+3970-GetCommonData("bgy")+448);
						DrawGraphic(224,240);
					}
					if(phase<=1&&time<100){SetAlpha(time*2.55);}
					if(phase>=2&&time>2700&&time<=2800){SetAlpha((2800-time)*2.55);}
					if(phase<=1||time<2800){
						SetTexture( GetCurrentScriptDirectory~"img\st4bg2.png" );
						SetGraphicRect(GetCommonData("bgx")*5,-GetCommonData("bgy")*5,GetCommonData("bgx")*5+384,-GetCommonData("bgy")*5+448);
						DrawGraphic(224,240);
						SetAlpha(255);
					}
				}
			}
			else if(stage==5){
				if(phase<=1){
					SetTexture( GetCurrentScriptDirectory~"img\st5bg1.png" );
					SetGraphicRect(GetCommonData("bgx")+288,1920-GetCommonData("bgy"),GetCommonData("bgx")+384+288,1920-GetCommonData("bgy")+449);
					DrawGraphic(224,240);
				}
				else if(phase==2){
					SetTexture( GetCurrentScriptDirectory~"img\st5bg2.png" );
					SetGraphicRect(GetCommonData("bgx"),1920-GetCommonData("bgy")+1800,GetCommonData("bgx")+384,1920-GetCommonData("bgy")+1800+448);
					DrawGraphic(224,240);
				}
				else if(phase==3){
					SetTexture( GetCurrentScriptDirectory~"img\st5bg3.png" );
					SetGraphicRect(GetCommonData("bgx")+624,1740-GetCommonData("bgy")+1800,GetCommonData("bgx")+624+384,1740-GetCommonData("bgy")+1800+448);
					DrawGraphic(224,240);
				}
				else if(phase==4){
					SetTexture( GetCurrentScriptDirectory~"img\st5bg4.png" );
					SetGraphicRect(GetCommonData("bgx"),-GetCommonData("bgy")+3360,GetCommonData("bgx")+384,-GetCommonData("bgy")+3360+448);
					DrawGraphic(224,240);
				}
				else if(phase==5){
					SetTexture( GetCurrentScriptDirectory~"img\st5bg5.png" );
					SetGraphicRect(GetCommonData("bgx")-816,-GetCommonData("bgy")+3360,GetCommonData("bgx")-816+384,-GetCommonData("bgy")+3360+448);
					DrawGraphic(224,240);
				}
				else if(phase==6){
					if(time<5200){
						SetTexture( GetCurrentScriptDirectory~"img\st5bg6.png" );
						SetGraphicRect(GetCommonData("bgx")-816,-GetCommonData("bgy")+4860,GetCommonData("bgx")-816+384,-GetCommonData("bgy")+4860+448);
						DrawGraphic(224,240);
					}
					else{
						SetTexture( GetCurrentScriptDirectory~"img\st5bg7.png" );
						SetGraphicRect(GetCommonData("bgx")-816,-GetCommonData("bgy")+7860,GetCommonData("bgx")-816+384,-GetCommonData("bgy")+7860+448);
						DrawGraphic(224,240);
					}
				}
				else if(phase==7){
					SetTexture( GetCurrentScriptDirectory~"img\st4bg3.png" );
					SetGraphicRect(0,-time*0.25,384,-time*0.25+448);
					DrawGraphic(224,240);
					
					SetTexture( GetCurrentScriptDirectory~"img\st4bg2.png" );
					SetGraphicRect(0,-time*0.4,384,-time*0.4+448);
					DrawGraphic(224,240);
					
					SetTexture( GetCurrentScriptDirectory~"img\st5bg7.png" );
					SetGraphicRect(GetCommonData("bgx")-816,-GetCommonData("bgy")+7860,GetCommonData("bgx")-816+384,-GetCommonData("bgy")+7860+448);
					DrawGraphic(224,240);
				}
			}
		}


		SetFontColor(255, 255, 255, 255, 255, 255);
		if(GetCommonData("kakusei")>0){
			let a=GetCommonData("kinkai");
			DrawText("+"~RealToIntString(a)~"",GetPlayerX+30,GetPlayerY-30,24,255);
		}
	}
	@DrawTopObject{
		/*
		let a=time;
		DrawText(""~ToString(a)~"",224,40,16,255);
		let a=GetCommonData("bgx");
		DrawText(""~ToString(a)~"",224,60,16,255);
		let a=GetCommonData("bgy");
		DrawText(""~ToString(a)~"",224,80,16,255);
		*/

		let a=GetCommonData("score");
		let b=10;
		let c=0;
		SetTexture( number );
		loop(11){
			c=a%10;
			a=truncate(a/10);
			SetGraphicRect( 0+c*32, 0, 32+c*32, 32 );
			SetGraphicScale( 0.7, 0.7 );
			DrawGraphic( 50+b*12, 40 );
			b--;
		}


		SetFontColor(255, 255, 255, 255, 255, 255);
		if(GetPlayerX>180||GetPlayerY>145){

			//c@
			let a=GetPlayerLife;
			let b=0;
			SetTexture( system );
			loop(a-1){
				c=a%10;
				a=truncate(a/10);
				SetGraphicRect( 0, 80, 31, 112 );
				SetGraphicScale( 0.6, 0.6 );
				DrawGraphic( 52+b*16, 61 );
				b++;
			}
			//{
			let a=GetPlayerBomb;
			let b=0;
			SetTexture( system );
			loop(a){
				c=a%10;
				a=truncate(a/10);
				SetGraphicRect( 32, 80, 64, 112 );
				SetGraphicScale( 0.6, 0.6 );
				DrawGraphic( 52+b*16, 80 );
				b++;
			}
			SetGraphicScale( 1, 1 );


			//
			SetGraphicRect( 0, 0, 16, 16 );
			DrawGraphic( 50, 100 );
			let a=GetPoint;
			DrawText(""~RealToIntString(a)~"",60,90,20,255);

			//
			SetGraphicRect( 16+16*3, 0, 32+16*3, 16 );
			DrawGraphic( 50, 120 );
			let a=GetCommonData("ruikei");
			DrawText(""~RealToIntString(a)~"",60,111,16,255);

			if(GetCommonData("kakusei")>0){
				let a=GetCommonData("kinkaiten");
				SetGraphicRect( 0, 32, a*2, 48 );
				DrawGraphic( 45+a, 136 );

			}
		}
		SetGraphicScale( 1, 1 );

		if(clearhyouzi>0){
			DrawText("STAGE CLEAR",clearhyouzi-240,150,40,255);
			let a=stage*20000000;
			DrawText("BONUS  "~RealToIntString(a)~" pts",-clearhyouzi+448+50,280,20,255);
		}
		if(stage==0){
			SetTexture( GetCurrentScriptDirectory~"img\title.png" );
			SetGraphicRect(0,0,384,480);
			DrawGraphic(224,240);
			SetGraphicRect(0,481,384,511);
			DrawGraphic(224,223+32*select);
			if(GetCommonData("autobomb")==true){SetGraphicRect(0,513,384,543);}
			else{SetGraphicRect(0,513+32,384,543+32);}
			DrawGraphic(224,380);
			if(GetCommonData("ex")==1){
				SetGraphicRect(0,481+96,384,511+96);
				DrawGraphic(224,150);
			}
		}
	}




	#include_function".\sfanc.txt"
	#include_function".\Stage1.txt"
	#include_function".\Stage2.txt"
	#include_function".\Stage3.txt"
	#include_function".\Stage4.txt"
	#include_function".\Stage5.txt"
}
