let kamek = "script\DanMUku\Stage5\Kamek.txt";
let j64 = "script\DanMUku\Stage4\J64enemy.txt";
let magi = "script\DanMUku\Stage5\Magikoopa.txt";
let helico = "script\DanMUku\Stage5\HelicoMaskass.txt";
let para = "script\DanMUku\Stage5\ParaMaskass.txt";
let fusee = "script\DanMUku\Stage5\MaskassFusee.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 Ini5() {
	LoadGraphic("script\DanMUku\Stage5\Image\inside.png");
	PlayMusic("script\DanMuku\Stage5\Stage5.mp3");
	SetCommonData("StageFini", false);
	SetCommonData("B", false);
	SetCommonData("O", false);
	SetCommonData("N", false);
	SetCommonData("U", false);
	SetCommonData("S", false);
	SetCommonData("nobonus", false);
	SetCommonData("madi", 0);
	SetCommonData("maskass", 0);
	LoadGraphic(b);
	LoadGraphic(o);
	LoadGraphic(n);
	LoadGraphic(u);
	LoadGraphic(s);
	LoadGraphic(bonus);
	 stage5;
  }


 function BG5() {
	    SetTexture("script\DanMUku\Stage5\Image\inside.png");
            SetRenderState(ALPHA);
            SetGraphicRect(0, 0, 384, 50000+q);
            SetGraphicScale(1,1);
            SetGraphicAngle(0, 0, 0);
            DrawGraphic(GetCenterX, GetCenterY);
		if (boss==false) {
			q-=2;
		}
	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("Don't get killed by the purple Magikoopa",GetCenterX-150,GetCenterY-110,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("Capture 'Delay Chase Combo'",GetCenterX-150,GetCenterY-30,16,255);

		SetTexture(u);
            SetGraphicRect(0,0,15,21);
            DrawGraphic(GetCenterX-170,GetCenterY+20);
		DrawText("Kill at least 80 Parasol Guy..",GetCenterX-150,GetCenterY+10,16,255);

		SetTexture(s);
            SetGraphicRect(0,0,16,23);
            DrawGraphic(GetCenterX-170,GetCenterY+60);
		DrawText("Capture at least 4 of Madi's Spell Card.",GetCenterX-150,GetCenterY+50,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 parashooters(n) {
	let a=[0,49,98,149];
	loop(n) {
		CreateEnemyFromFile(para, GetClipMinX+rand(0, 400), GetClipMinY, 0.5, 90, a[rand_int(0,3)]);
		Wait(rand_int(20,30));
	}


}

task J64(n, w){
	loop(n) {
		CreateEnemyFromFile(j64, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
		Wait(w);
		CreateEnemyFromFile(j64, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
		Wait(w);
	}
}

task K(n, w){
	loop(n) {
		CreateEnemyFromFile(kamek, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
		Wait(w);
		CreateEnemyFromFile(kamek, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
		Wait(w);
	}
}

 task stage5{
	Wait(60);
	CreateEnemyFromFile(para, GetCenterX, GetClipMinY, 0.5, 90, 49);
	Wait(15);
	CreateEnemyFromFile(para, GetCenterX+120, GetClipMinY, 0.5, 90, 0);
	Wait(15);
	CreateEnemyFromFile(para, GetCenterX-45, GetClipMinY, 0.5, 90, 98);
	Wait(10);
	CreateEnemyFromFile(para, GetCenterX+45, GetClipMinY, 0.5, 90, 149);
	Wait(5);
	CreateEnemyFromFile(para, GetCenterX+150, GetClipMinY, 0.5, 90, 49);
	Wait(10);
	CreateEnemyFromFile(para, GetCenterX-150, GetClipMinY, 0.5, 90, 49);
	Wait(15);
	CreateEnemyFromFile(para, GetCenterX-90, GetClipMinY, 0.5, 90, 149);
	Wait(5);
	CreateEnemyFromFile(para, GetCenterX-120, GetClipMinY, 0.5, 90, 0);
	Wait(15);
	CreateEnemyFromFile(para, GetCenterX+90, GetClipMinY, 0.5, 90, 98);
	Wait(400);
	CreateEnemyFromFile(fusee, GetClipMaxX+30, GetCenterY-20, 0, 180, 0);
	Wait(20);
	CreateEnemyFromFile(fusee, 0, GetCenterY-50, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(fusee, GetCenterX+150, GetClipMinY-30, 0, 90, 0);
	Wait(250);
	CreateEnemyFromFile("script\DanMUku\Stage5\Dialogue.txt", 80, GetClipMaxY+20, 3, 270, 0);
	Wait(900);
	CreateEnemyFromFile(para, GetCenterX+150, GetClipMinY, 0.5, 90, 49);
	CreateEnemyFromFile(para, GetCenterX-150, GetClipMinY, 0.5, 90, 98);
	Wait(100);
	CreateEnemyFromFile(para, GetCenterX+150, GetClipMinY, 0.5, 90, 149);
	CreateEnemyFromFile(para, GetCenterX-150, GetClipMinY, 0.5, 90, 0);
	Wait(150);
	CreateEnemyFromFile(para, GetCenterX+150, GetClipMinY, 0.5, 90, 49);
	CreateEnemyFromFile(para, GetCenterX-150, GetClipMinY, 0.5, 90, 98);
	Wait(100);
	CreateEnemyFromFile(kamek, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	Wait(100);
	CreateEnemyFromFile(kamek, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(100);
	CreateEnemyFromFile(kamek, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	Wait(100);
	CreateEnemyFromFile(kamek, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	Wait(100);
	CreateEnemyFromFile(kamek, GetClipMinX, rand(50,150), 5, rand(-10,10), 0);
	Wait(100);
	CreateEnemyFromFile(kamek, GetClipMaxX, rand(50,150), 5, rand(170,190), 0);
	CreateEnemyFromFile(para, GetCenterX+100, GetClipMinY, 0.5, 90, 149);
	CreateEnemyFromFile(para, GetCenterX-100, GetClipMinY, 0.5, 90, 0);
	Wait(150);
	CreateEnemyFromFile(fusee, GetClipMaxX+30, GetCenterY-50, 0, 150, 0);
	Wait(50);
	CreateEnemyFromFile(fusee, 0, GetCenterY-80, 0, 50, 0);
	Wait(50);
	CreateEnemyFromFile(fusee, GetCenterX+10, GetClipMinY-30, 0, 100, 0);
	Wait(150);
	CreateEnemyBossFromFile(magi, GetClipMaxX, GetCenterY-120, 4, 180, 0);
	WaitForZeroEnemy;
	Wait(100);
	CreateEnemyFromFile(para, GetCenterX+150, GetClipMinY, 0.5, 90, 49);
	CreateEnemyFromFile(para, GetCenterX-150, GetClipMinY, 0.5, 90, 98);
	Wait(100);
	CreateEnemyFromFile(para, GetCenterX+150, GetClipMinY, 0.5, 90, 149);
	CreateEnemyFromFile(para, GetCenterX-150, GetClipMinY, 0.5, 90, 0);
	Wait(150);
	CreateEnemyFromFile(para, GetCenterX+150, GetClipMinY, 0.5, 90, 49);
	CreateEnemyFromFile(para, GetCenterX-150, GetClipMinY, 0.5, 90, 98);
	Wait(200);
	J64(4, 120);
	let a = 40;
	loop(2){
		CreateEnemyFromFile(helico, GetClipMinX, GetCenterY-100, 1, a, 0);
		a-=20;
		Wait(40);
	}
	Wait(60);
	CreateEnemyFromFile("script\DanMUku\Stage5\1UPMaskass.txt", GetCenterX, GetClipMinY, 2, 110, "O");
	Wait(40);
	a=-230;
	loop(2){
		CreateEnemyFromFile(helico, GetClipMaxX, GetCenterY-120, 1, a, 0);
		a+=20;
		Wait(40);
	}
	Wait(200);
	CreateEnemyFromFile(fusee, GetCenterX+60, GetClipMinY-30, 0, 120, 0);
	CreateEnemyFromFile(fusee, GetCenterX-40, GetClipMinY-30, 0, 60, 0);
	Wait(600);
	boss=true;
	CreateEnemyBossFromFile("script\DanMUku\Stage5\Seud.txt", 100, 0, 0, 0, 0);
	WaitForZeroEnemy;
	boss=false;
	Wait(100);
	parashooters(20);
	Wait(100);
	J64(4, 160);
	Wait(20);
	K(4, 150);
	Wait(1200);
	CreateEnemyFromFile("script\DanMUku\Stage5\Dialogue3.txt", 250, GetClipMinY-10, 1, 90, 0);
	Wait(600);
	loop(20) {
		let distance = rand_int(0, 1000);
		let x = GetClipMinX;
		let y = GetClipMinY;
		let angle;
		alternative(rand_int(0,1))
		case(0) {
			y+=distance;
			if (y>GetClipMaxY) {
				x+=y-GetClipMaxY;
				y=GetClipMaxY+30;
				angle = rand(190, 350);
			}
			else {
				x=GetClipMinX-30;
				angle = rand(280, 440);
			}
		}
		case(1) {
			x+=distance;
			if (x>GetClipMaxX) {
				y+=x-GetClipMaxX;
				x = GetClipMaxX+30;
				angle = rand(100, 260);
			}
			else {
				y = GetClipMinY-30;
				angle = rand(10, 170);
			}
		}
		CreateEnemyFromFile(fusee, x, y, 0, angle, 0);
		Wait(40);
	}	
	Wait(200);
	parashooters(50);
	Wait(2200);
	boss=true;
	CreateEnemyBossFromFile("script\DanMUku\Stage5\Madi.txt", 100, 0, 0, 0, 0);
	WaitForZeroEnemy;
	boss=false;
	if (GetCommonData("madi")>=4) {
		SetCommonData("S", true);
	}
	Wait(100);
	let a = 70;
	loop(6){
		CreateEnemyFromFile(helico, GetClipMinX, GetCenterY-100, 1, a, 0);
		a-=20;
		Wait(70);
	}
	Wait(360);
	a=-250;
	loop(6){
		CreateEnemyFromFile(helico, GetClipMaxX, GetCenterY-120, 1, a, 0);
		a+=20;
		Wait(70);
	}
	Wait(360);

	let a = 80;
	loop(6){
		CreateEnemyFromFile(helico, GetClipMinX, GetCenterY-100, 1, a, 0);
		a-=20;
		Wait(40);
	}
	Wait(200);
	a=-260;
	loop(6){
		CreateEnemyFromFile(helico, GetClipMaxX, GetCenterY-120, 1, a, 0);
		a+=20;
		Wait(40);
	}

	Wait(800);
	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\Stage5\Bonus5.txt", GetCenterX, GetClipMinY, 0, 0, numberBonus);
		gotbonus=false;
		WaitForZeroEnemy;
		Wait(100);
	}

	boss=true;
	alternative(GetPlayerScriptName)
	case("KorHosik.txt") {
		CreateEnemyBossFromFile("script\DanMUku\Stage5\Full_KorbeA.txt", 100, 0, 0, 0, 0);
	}
	case("KorB.txt") {
		CreateEnemyBossFromFile("script\DanMUku\Stage5\Full_KorbeB.txt", 100, 0, 0, 0, 0);
	}
	case("KorC.txt") {
		CreateEnemyBossFromFile("script\DanMUku\Stage5\Full_KorbeC.txt", 100, 0, 0, 0, 0);
	}

	WaitForZeroEnemy;
	Wait(120);
	boss=false;


SetCommonData("StageFini", true);
 }
