#TouhouDanmakufu
#Title[Noob Man : "Moderation : Ban on the founder"]
#Text[La derniere attaque de Noob Man. Il sort l'artillerie lourde et tente de vous bannir. Bien sur, il n'est pas si simple de bannir le createur du forum, vous pouvez encore le battre ! Bonne chance !]
#Image[]
#Player[script\DanMUku\Joueur\KorA\KorHosik.txt, script\DanMUku\Joueur\KorB\KorB.txt, script\DanMUku\Joueur\KorC\KorC.txt]
#ScriptVersion[2]

script_enemy_main
{    
    let imgEnemy="script\DanMUku\Stage6\Image\noobman.png";
    let count=-100;
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let bg = "script\DanMUku\Stage6\Image\fondchapeau.png";
    let laser ="script\DanMUku\Stage2\Son\laser.wav"; 
    let x = GetX;
    let q = 0;
    let phase = -1;
    let anglePluie = 90;
    let changePluie = 1;
    let phaseParVie = 0;


 function Wait(let frames){
   loop(frames){yield;}
 }


   @Initialize
   {
      LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
      LoadGraphic(imgEnemy);
	LoadGraphic(bg);
      LoadSE(tir);
      LoadSE(munch);
      LoadSE(laser);
      PlayMusic("script\DanMUku\Stage6\FinalNoob.mp3");
            SetLife(18000);
            SetTimer(120);
            SetInvincibility(120);
	SetScore(6000000);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY-100 , 60);
	    SetEffectForZeroLife(60,200,2); 
	CutIn(YOUMU, "Moderation"\""Ban on the founder"\", "script\DanMUku\Stage6\Image\noobcutin.png" , 0,0,121,214);
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);
	SetDamageRate(100,0);

	if (phase>=0&&count%5==0) {
		CreateShot01(rand(0,448), 0, rand(3,4), anglePluie, 74+(changePluie+1)/2, 0); 
		anglePluie+=changePluie;
		if (anglePluie>140) {
			anglePluie=120;
			changePluie = -1;
		}
		if (anglePluie<40) {
			anglePluie=60;
			changePluie = 1;
		}
	}


	if (phase>=1&&phase<=2) {
		if (count%60==0) {
			PlaySE(laser);
			CreateLaser01(GetX+60-2*(count%120), GetY, 3, atan2(-GetY+GetPlayerY, -GetX-60+2*(count%120)+GetPlayerX), 100, 7, 13, 20);
		}
	}

	if (phase>=2&&count%300==0) {
		PlaySE(tir);
		ascent (i in 0..5) {
			CreateEnemyFromFile("script\DanMUku\Stage6\Chapeau.txt", GetX, GetY, 2, GetAngleToPlayer+180+i*72, [2,90]);
		}
	}

	if (phase>=3&&count%200==100) {
		ascent (i in 0..24) {
			CreateLaserB(1, 400, 10, 2, 42);
			SetLaserDataB(1, 0, 0, 60, 0, GetAngleToPlayer+7+i*15, 0, GetAngleToPlayer+7+i*15, 0);
			SetShotKillTime(1, 90);
			FireShot(1);
		}
	}

	if (phase>=4&&count%200==0) {
		ascent (i in 0..24) {
			CreateLaserB(1, 400, 10, 8, 42);
			SetLaserDataB(1, 0, 0, 60, 0, GetAngleToPlayer+i*15, 0, GetAngleToPlayer+i*15, 0);
			SetShotKillTime(1, 90);
			FireShot(1);
		}
	}

	if (phase>=5&&count%500==50) {
		ascent (i in 0..9) {
			CreateLaserB(2, 400, 10, 7, 42);
			SetLaserDataB(2, 0, 0, 60, 0, GetAngleToPlayer+i*(360/9), 0, GetAngleToPlayer+rand(-10, 10), 0);
			SetShotKillTime(2, 90);
			FireShot(2);
		}
	}

	if (count==120*60-300) {
		PlaySE(munch);
		ascent (i in 0..360) {
			CreateShot01(GetX, GetY, 1, i, 85, 0);
		}
	}

	if ( (phase>=3&&count%200==135) || (phase>=4&&count%200==35) || (phase>=5&&count%500==85) ) {
		PlaySE(laser);
	}


	if (count==0||count==200||count==1200||count==2400||count==2900||count==5400||count==6300) {
		phase++;
	}

	if ( (GetLife<14000 && phaseParVie<1) || (GetLife<8000 && phaseParVie<2) ) {
		phase++;
		phaseParVie++;
	}

count++;
yield;
   }
   @Finalize
   {
      DeleteGraphic(imgEnemy);

	loop(9) {
		CreateItem(ITEM_SCORE, rand(GetX-10, GetX+10), rand(GetY-10, GetY+10));  
	}
   }
   

   @DrawLoop
   {

	    SetTexture(bg);
            SetRenderState(ALPHA);
            SetAlpha(255);
            SetGraphicRect(0, 0, 50000+q, 50000+q);
            SetGraphicScale(1,1);
	    SetColor(50, 50, 50);
            SetGraphicAngle(0, 0, 0);
            DrawGraphic(GetCenterX+q, GetCenterY+q);
		q--;

	if(x<GetX){
		SetGraphicAngle(0,0,0);
	}
	if(x>GetX){
		SetGraphicAngle(180,0,0);
	}
      x=GetX;
            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(imgEnemy);
	if (GetSpeed>0) {	
	            SetGraphicRect(28,0,55,34);
	}
	else {
		    SetGraphicRect(0,0,27,34);
	}

            DrawGraphic(GetX,GetY);

	DrawText("Noob Man", GetClipMinX+10, GetClipMinY+15, 12, 255);

	//let i = 0;
	//loop(length(string)) {
	//	DrawText(string[i], GetClipMinX+10, GetClipMinY+35+20*i, 12, 255);
	//	i++;
	//}
   }





}
