#TouhouDanmakufu
#Title[Noob Man : "Rotary lasers"]
#Text[Noob Man vous force a tourner autour de lui avec ses lasers. Tournez vite pour avoir le plus de temps en-dessous de lui pour lui tirer dessus. Sauf si vous pouvez lui tirer depuis n'importe ou bien sur. On ne le voit plus, mais Noob Man est bien au milieu en fait.]
#Image[]
#BGM[script\DanMUku\Stage6\NoobMan.mp3]
#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 laser ="script\DanMUku\Stage2\Son\laser.wav";
    let bg = "script\DanMUku\Stage6\Image\dedale.png";
    let x = GetX;
    let q = 0;
	let a = 0;
	let phase=1;


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


   @Initialize
   {
      LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
      LoadGraphic(imgEnemy);
	LoadGraphic(bg);
      LoadSE(tir);
      LoadSE(laser);
            SetLife(8000);
            SetTimer(100);
            SetInvincibility(60);
	SetScore(2000000);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY , 60);
	CutIn(YOUMU, "Rotary lasers", "script\DanMUku\Stage6\Image\noobcutin.png" , 0,0,121,214);
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);
	SetDamageRate(100,50);

	if (count==0) {
		ascent(i in 0..4) {
			CreateLaserB(i, 0, 20, 1, 150);
			SetLaserDataB(i, 0, 2, 20, 0, i*90, 0.5, i*90, 0.5);
			SetLaserDataB(i, 150, 0, 20, 0, NULL, 0.5, NULL, 0.5);
			FireShot(i);
		}
	}

	if (count==135) {
		PlaySE(laser);
	}

	if (count==300) {
		a=GetAngleToPlayer;
	}

	if (phase==1) {

		if (count>300&&count%12==0) {
			PlaySE(tir);
			ascent (i in 0..3) {
				CreateShot01(GetX, GetY, 2+i*0.3, a, 9, 0);
			}
		}

		if (count>600&&count%12==2) {
			ascent (i in 0..3) {
				CreateShot01(GetX, GetY, 2+i*0.1, a+i*2+90, 10, 0);
			}
		}

		if (count>900&&count%12==6) {
			ascent (i in 0..3) {
				CreateShotA(1, GetX, GetY, 0);
				SetShotDataA(1, 0, 2-i*0.05, a-100, 0.2, 0, 0, 14);
				FireShot(1);
			}
		}

		if (count>1200&&count%12==8) {
			ascent (i in 0..3) {
				CreateShotA(1, GetX, GetY, 0);
				SetShotDataA(1, 0, 2+i*0.05, a-80, -0.2, 0, 0, 18);
				FireShot(1);
			}
		}

		if (count>1500&&count%12==4) {
			ascent (i in 0..3) {
				CreateShot01(GetX, GetY, 2-i*0.1, a+180+i*2, 22, 0);
			}
		}
	
		if (count>300&&count%12==9) {
			a-=14.3;
		}

	}

	if (phase==2) {

		if (count==4100) {
			ascent(i in 0..4) {
				CreateEnemyFromFile("script\DanMUku\Stage6\Noob Man SC04-Familier.txt", GetX, GetY, 2, 45+i*90, [6,10+i*2,-1^i,150]);
			}
		}

		if (count==4500) {
			ascent(i in 0..4) {
				CreateEnemyFromFile("script\DanMUku\Stage6\Noob Man SC04-Familier.txt", GetX, GetY, 0.5, i*90, [4,11+i*4,-1^i,100]);
			}
		}

	}

	if (phase==1&&(count==4000||GetLife<3000)) {
		DeleteEnemyShot(SHOT);
		phase=2;
		Concentration01(100);
		count=4000;
	}

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);
            SetColor(55,55,55);
            SetGraphicRect(0, 0, 1296, 1296);
            SetGraphicScale(0.5,0.5);
            SetGraphicAngle(0, 0, q);
            DrawGraphic(GetCenterX, GetCenterY);
	q+=0.5;

	SetGraphicAngle(0,0,0);
	if(x<GetX){
		SetGraphicAngle(0,0,0);
	}
	if(x>GetX){
		SetGraphicAngle(180,0,0);
	}
      x=GetX;
            SetGraphicScale(1,1);
            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++;
	//}
   }


}
