let j64 = "script\DanMUku\Stage4\J64enemy.txt";
let lakitu="script\DanMUku\Stage4\Lakitu.txt";
let Koopa2 = "script\DanMUku\Stage3\ParaKoopaM.txt";
let Koopa1 = "script\DanMUku\Stage3\ParaKoopaV.txt";
let b ="script\DanMUku\Image\b.png";
let o ="script\DanMUku\Image\o.png";
let n ="script\DanMUku\Image\n.png";
let u ="script\DanMUku\Image\u.png";
let s="script\DanMUku\Image\s.png";
let bonus="script\DanMUku\Image\bonus.png";
let gotbonus=false;
let count=0;
let q=0;
let boss=false;

#include_script "script\DanMUku\Wait.txt";

 function Ini4() {
	LoadGraphic("script\DanMUku\Stage4\Image\tower.png");
	PlayMusic("script\DanMuku\Stage4\Stage4.mp3");
	SetCommonData("StageFini", false);
	SetCommonData("B", false);
	SetCommonData("O", false);
	SetCommonData("N", false);
	SetCommonData("U", false);
	SetCommonData("S", false);
	SetCommonData("nobonus", false);
	SetCommonData("lakitu", 0);
	LoadGraphic(b);
	LoadGraphic(o);
	LoadGraphic(n);
	LoadGraphic(u);
	LoadGraphic(s);
	LoadGraphic(bonus);
	 stage4;
  }


 function BG4() {
	    SetTexture("script\DanMUku\Stage4\Image\tower.png");
            SetRenderState(ALPHA);
            SetGraphicRect(0, 0, 384, 50000+q);
            SetGraphicScale(1,1);
            SetGraphicAngle(0, 0, 0);
            DrawGraphic(GetCenterX, GetCenterY);
		if (boss==false) {
			q-=6;
		}

	
	if(GetCommonData("B")){
		SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(b);
            SetGraphicRect(0,0,14,21);
            DrawGraphic(GetClipMaxX-90,GetClipMaxY-10);
	}
	if(GetCommonData("O")){
		SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(o);
            SetGraphicRect(0,0,19,20);
            DrawGraphic(GetClipMaxX-70,GetClipMaxY-10);
	}
	if(GetCommonData("N")){
		SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(n);
            SetGraphicRect(0,0,15,20);
            DrawGraphic(GetClipMaxX-50,GetClipMaxY-10);
	}
	if(GetCommonData("U")){
		SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(u);
            SetGraphicRect(0,0,15,21);
            DrawGraphic(GetClipMaxX-30,GetClipMaxY-10);
	}
	if(GetCommonData("S")){
		SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(s);
            SetGraphicRect(0,0,16,23);
            DrawGraphic(GetClipMaxX-10,GetClipMaxY-10);
	}
	if(GetCommonData("nobonus")){
		SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(b);
            SetGraphicRect(0,0,14,21);
            DrawGraphic(GetCenterX-170,GetCenterY-100);
		DrawText("Finish Statiated sign 'Or not...'",GetCenterX-150,GetCenterY-120,16,255);
		DrawText("with 5 or fewer seconds left.",GetCenterX-150,GetCenterY-100,16,255);

		SetTexture(o);
            SetGraphicRect(0,0,19,20);
            DrawGraphic(GetCenterX-170,GetCenterY-60);
		DrawText("Kill the bonus Shy Guy.",GetCenterX-150,GetCenterY-70,16,255);

		SetTexture(n);
            SetGraphicRect(0,0,15,20);
            DrawGraphic(GetCenterX-170,GetCenterY-20);
		DrawText("Defeat 5 lakitus.",GetCenterX-150,GetCenterY-30,16,255);

		SetTexture(u);
            SetGraphicRect(0,0,15,21);
            DrawGraphic(GetCenterX-170,GetCenterY+20);
		DrawText("Capture Flower Sign",GetCenterX-150,GetCenterY,16,255);
		DrawText("'The Flower enchanting the butterfly'.",GetCenterX-150,GetCenterY+20,16,255);

		SetTexture(s);
            SetGraphicRect(0,0,16,23);
            DrawGraphic(GetCenterX-170,GetCenterY+60);
		DrawText("Don't lose any life on",GetCenterX-150,GetCenterY+40,16,255);
		DrawText("Star sign 'Deathly pentagram'.",GetCenterX-150,GetCenterY+60,16,255);
	}

		if(gotbonus&&count%60<40){
			SetTexture(bonus);
		    SetRenderState(ALPHA);
		    SetAlpha(255);
		    SetGraphicRect(0, 0, 150, 80);
			SetGraphicScale(1,1);
            		SetGraphicAngle(0, 0, 0);
			DrawGraphic(GetCenterX, GetCenterY-50);
	}
 }

 task stage4{
	Wait(60);
	CreateEnemyFromFile("script\DanMUku\Stage4\j64tombe.txt", GetClipMaxX, GetCenterY, 4, 200, 0);
	Wait(100);
	CreateEnemyFromFile(Koopa2, GetClipMinX+100, GetClipMinY, 1, 90, 1);
	CreateEnemyFromFile(Koopa2, GetClipMaxX-100, GetClipMinY, 1, 90, 0);
	Wait(60);
	CreateEnemyFromFile(Koopa1, GetClipMinX, GetCenterY-50, 1, 0, 1);
	CreateEnemyFromFile(Koopa1, GetClipMaxX, GetCenterY+50, 1, 180, 0);
	Wait(300);
	CreateEnemyFromFile(Koopa1, GetClipMinX, GetCenterY+50, 1, 0, 1);
	CreateEnemyFromFile(Koopa1, GetClipMaxX, GetCenterY-50, 1, 180, 0);
	Wait(600);
	CreateEnemyFromFile("script\DanMUku\Stage4\Dialogue.txt", GetClipMinX, GetCenterY+50, 4, 320, 0);
	Wait(1100);
	CreateEnemyFromFile(Koopa2, GetClipMaxX, 100, 1, 180, 0);
	CreateEnemyFromFile(lakitu, GetClipMinX, 100, 1, 0, 1);
	Wait(900);
	CreateEnemyFromFile(j64, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(100);
	CreateEnemyFromFile(Koopa1, GetClipMinX, GetCenterY-50, 1, 0, 1);
	CreateEnemyFromFile(Koopa1, GetClipMaxX, GetCenterY+50, 1, 180, 0);
	CreateEnemyFromFile(j64, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(100);
	CreateEnemyFromFile(Koopa1, GetClipMinX, GetClipMinY, 1, 45, 1);
	CreateEnemyFromFile(Koopa1, GetClipMaxX, GetClipMinY, 1, 105, 0);
	CreateEnemyFromFile(j64, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(400);
	CreateEnemyBossFromFile("script\DanMUku\Stage4\j64.txt", 0, 200, 0, 0, 0);
	WaitForZeroEnemy;
	Wait(100);
	CreateEnemyFromFile(lakitu, GetClipMaxX, 50, 2, 180, 0);
	Wait(300);
	CreateEnemyFromFile(lakitu, GetClipMinX, 50, 2, 10, 0);
	Wait(200);
	CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	CreateEnemyFromFile(lakitu, GetCenterX, GetClipMinY, 1, 90, 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(100);
	CreateEnemyFromFile("script\DanMUku\Stage5\1UPMaskass.txt", GetClipMaxX, GetCenterY, 2, 190, "O");
	CreateEnemyFromFile(j64, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	CreateEnemyFromFile(lakitu, GetClipMaxX, 100, 1, 200,0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	CreateEnemyFromFile(lakitu, GetClipMinX, 100, 1, -20, 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(100);
	CreateEnemyFromFile(j64, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	Wait(1000);
	boss=true;
	CreateEnemyBossFromFile("script\DanMUku\Stage4\FdRstar.txt", 0, 200, 0, 0, 0);
	WaitForZeroEnemy;
	AddScore(4000000);
	Wait(100);
	boss=false;

	SetCommonData("nobonus", true);
	Wait(300);
	SetCommonData("nobonus", false);

	let numberBonus = 0;
	ascent (i in 0..5) {
		if (GetCommonData(["B", "O", "N", "U", "S"][i])) {
			numberBonus++;
		}
	}

	if (numberBonus>=3) {
		gotbonus= true;
		count=0;
		PlayMusic("script\DanMUku\Musique\bonus.mp3");
		Wait(200);
		CreateEnemyBossFromFile("script\DanMUku\Stage4\Bonus4.txt", GetCenterX, GetClipMinY, 0, 0, numberBonus);
		gotbonus=false;
		WaitForZeroEnemy;
		Wait(100);
	}



SetCommonData("StageFini", true);
 }
