#TouhouDanmakufu[Stage]
#Title[DanMUku]
#Text[]
#Image[]
#BackGround[]
#Player[script\DanMUku\Joueur\KorA\KorHosik.txt, script\DanMUku\Joueur\KorB\KorB.txt, script\DanMUku\Joueur\KorC\KorC.txt]
#ScriptVersion[2]

script_stage_main{

let stage = 1;
let scoreDraw = false;

#include_script "script\DanMUku\Stage1\Stage1Include.txt"
#include_script "script\DanMUku\Stage2\Stage2Include.txt"
#include_script "script\DanMUku\Stage3\Stage3Include.txt"
#include_script "script\DanMUku\Stage4\Stage4Include.txt"
#include_script "script\DanMUku\Stage5\Stage5Include.txt"
#include_script "script\DanMUku\Stage6\Stage6Include.txt"
#include_script "script\DanMUku\MauvaiseFin.txt"
#include_script "script\DanMUku\BonneFin.txt"

  @Initialize{
//CreateDebugWindow;
  Ini1;
  }

  @MainLoop{

	if (GetCommonData("StageFini")) {
		stage++;
		alternative(stage)
		case(2) { Ini2; }
		case(3) { Ini3; }
		case(4) { Ini4; }
		case(5) { Ini5; }
		case(6) { Ini6; }
		case(7) { 
			FinalScore;
		}
		case(8) {
			PlayMusic("script\DanMUku\Musique\credit.mp3");
			SetCommonData("StageFini", false);
			if (Continued) {
				MauvaiseFin;
			}
			else {
				BonneFin;
			}
		}
	}

count++;
yield;
  }
   @BackGround{

		alternative(stage)
		case(1) { BG1; }
		case(2) { BG2; }
		case(3) { BG3; }
		case(4) { BG4; }
		case(5) { BG5; }
		case(6) { BG6; }

	if (scoreDraw) {
			SetTexture("score"); 
			SetGraphicRect(0,0,300,300); 
			DrawGraphic(GetCenterX, GetCenterY);
	}


  }
   @DrawLoop{

}

	function IntToString(n) {
		let string = ToString(n);
		let res = "";
		let i = 0;
		loop {
			if (string[i]=='.') {
				return res;
			}
			res=res~ToString(string[i]);
			i++;
		}
	}

	task FinalScore() {
		SetCommonData("StageFini", false);
		let stay = true;

		let scoreBase = GetScore;
		let points = GetPoint;
		let graze = GetGraze;
		let lives = GetPlayerLife;

		let scoreFinal = scoreBase + 100*points*graze + 10000000*lives;

			CreateRenderTarget("score", 300, 300);
			SetRenderTarget("score");

			DrawText("Score :  "~IntToString(scoreBase), 0, 20, 24, 255 );
			DrawText("Base :    +100", 0, 50, 24, 255 );
			DrawText("Points :  * "~IntToString(points), 0, 80, 24, 255  );
			DrawText("Graze :  * "~IntToString(graze), 0, 110, 24, 255  );
			DrawText("Lives : + 10000000 * "~IntToString(lives), 0, 140, 24, 255  );
			DrawText("Total : "~IntToString(scoreFinal), 0, 180, 24, 255  );

		SetRenderTarget("DEFAULT");
		scoreDraw = true;

		AddScore(100*points*graze + 10000000*lives);

		while(stay) {

			if (GetKeyState(VK_SHOT)==KEY_PUSH) {
				stay = false;
			}
			yield;

		}
		scoreDraw = false;
		SetCommonData("StageFini", true);
	}



  @Finalize{

  }
}
