let count=0;
let q=0;
let boss=false;
let chauvesouris = "script\DanMUku\Stage6\ChauveSouris.txt";
let chauvesourisH = "script\DanMUku\Stage6\ChauveSourisH.txt";
let nuage = "script\DanMUku\Stage6\Nuage.txt";
let change = false;
let alpha = 255;
let changed = false;

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

 function Ini6() {
	LoadGraphic("script\DanMUku\Stage5\Image\inside.png");
	LoadGraphic("script\DanMUku\Stage6\Image\final.png");
	SetCommonData("StageFini", false);
	 stage6;
  }


 function BG6() {

	if (!changed) {
	    SetTexture("script\DanMUku\Stage5\Image\inside.png");
            SetRenderState(ALPHA);
            SetGraphicRect(0, 0, 384, 50000+q);
            SetGraphicScale(1,1);
            SetGraphicAngle(0, 0, 0);
	    SetAlpha(alpha);
		if (alpha<0) {
			SetAlpha(0);
		}
            DrawGraphic(GetCenterX, GetCenterY);
		if (boss==false) {
			q+=5;
		}
	}
	else {
	    SetTexture("script\DanMUku\Stage6\Image\final.png");
            SetRenderState(ALPHA);
            SetGraphicRect(0, 0, 384, 448);
            SetGraphicScale(1,1);
            SetGraphicAngle(0, 0, 0);
	    SetAlpha(alpha);
            DrawGraphic(GetCenterX, GetCenterY);
	}

	if (change) {
		if (!changed) {
			alpha -=3;
		}
		else {
			alpha+=3;
			if (alpha>255) {
				alpha=255;
			}
		}
		if (alpha<-100) {
			changed=true;
			alpha=0;
		}
	}

 }

task Boule(x, longueur) {
	CreateEnemyFromFile("script\DanMUku\Stage6\Boule.txt", x, GetClipMinY, 1, 90, longueur);
}

task EnsembleLigne(x, espace, nombre, lignes, attente) {
	loop(lignes){
		LigneNuage(x, espace, nombre);
		Wait(attente);
	}
}

task LigneNuage(x, espace, nombre) {
	let i = 0;
	loop(nombre) {
		CreateEnemyFromFile(nuage, x+i*espace, GetClipMinY, 0.5, 90, 0);
		i++;
	}
}

task Chauves(x, ymax, ymin, v, anglemin, anglemax, nombre, attente) {
	loop(nombre){
		CreateEnemyFromFile(chauvesouris, x, rand(ymin, ymax), v, rand(anglemin, anglemax), 0);
		Wait(attente);
	}
}

task ChauvesH(x, ymin, ymax, v, anglemin, anglemax, nombre, attente) {
	loop(nombre){
		CreateEnemyFromFile(chauvesourisH, x, rand(ymin, ymax), v, rand(anglemin, anglemax), 0);
		Wait(attente);
	}
}

 task stage6{
	Wait(60);
	ChauvesH(GetClipMinX, GetCenterY, GetCenterY-200, 2, 300, 350, 24, 15);
	Wait(400);
	ChauvesH(GetClipMaxX, GetCenterY, GetCenterY-200, 2, 190, 240, 24, 15);
	Wait(500);
	Chauves(GetClipMinX, GetCenterY, GetCenterY-200, 2, 300, 350, 24, 15);
	Wait(400);
	Chauves(GetClipMaxX, GetCenterY, GetCenterY-200, 2, 190, 240, 24, 15);
	Wait(500);
	Chauves(GetClipMinX, GetCenterY, GetCenterY-200, 2, 300, 350, 20, 15);
	ChauvesH(GetClipMinX, GetCenterY, GetCenterY-200, 2, 300, 350, 8, 15);
	Wait(500);
	DeleteAllEnemyWithoutBoss;
	CreateEnemyBossFromFile("script\DanMUku\Stage6\Inconnu.txt", 0, 0, 0, 0, 0);
	WaitForZeroEnemy;
	Wait(100);
	EnsembleLigne(GetClipMinX+10, 40, 10, 5, 200);
	Wait(1500);
	EnsembleLigne(GetClipMinX+10, 60, 7, 5, 200);
	Wait(400);
	Chauves(GetClipMinX, GetCenterY, GetCenterY-200, 2, 300, 350, 14, 15);
	Wait(600);
	Chauves(GetClipMaxX, GetCenterY, GetCenterY-200, 2, 190, 240, 12, 15);
	ChauvesH(GetClipMaxX, GetCenterY, GetCenterY-200, 2, 190, 240, 4, 15);
	Wait(700);
	Boule(100, 80);
	Boule(200, 160);
	Boule(300, 40);
	Wait(1200);
	Boule(GetCenterX, 170);
	Wait(300);
	Chauves(GetClipMinX, GetCenterY-100, GetCenterY-250, 2, 10, 50, 16, 15);
	Wait(200);
	Boule(GetCenterX+80, 100);
	Wait(300);
	Chauves(GetClipMaxX, GetCenterY-100, GetCenterY-250, 2, 130, 170, 16, 15);
	Wait(1000);
	CreateEnemyBossFromFile("script\DanMUku\Stage6\MachinJ64.txt", 0, 0, 0, 0, 0);
	WaitForZeroEnemy;
	Wait(200);
	EnsembleLigne(GetClipMinX, 40, 10, 9, 400);
	Wait(1200);
	Boule(GetCenterX-200, 90);
	Wait(500);
	Boule(GetCenterX+100, 140);
	Wait(1000);
	ChauvesH(GetClipMaxX, GetCenterY, GetCenterY-200, 2, 190, 240, 18, 25);
	ChauvesH(GetClipMinX, GetCenterY-100, GetCenterY-250, 2, 10, 40, 18, 25);
	Wait(1200);
	Chauves(GetClipMinX, GetCenterY-200, GetCenterY-350, 2, 70, 90, 12, 15);
	Wait(50);
	Chauves(GetClipMaxX, GetCenterY-200, GetCenterY-350, 2, 90, 110, 12, 15);
	Wait(600);
	change=true;
	Wait(500);
	CreateEnemyBossFromFile("script\DanMUku\Stage6\Noob Man.txt", 300, 0, 0, 0, 0);
	WaitForZeroEnemy;
	Wait(200);

SetCommonData("StageFini", true);
 }
