#TouhouDanmakufu
#Title[Noob Man : "Entropic sign : Initial explosion"]
#Text[Une simple explosion de projectiles. Enfin, "simple". Les projectiles sont de plus en plus rapides. Cette attaque met a l'epreuve vos reflexes avec ses tirs rapides et de direction aleatoire.]
#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 munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let dir=0;
    let vitesse=0.2;
    let bg = "script\DanMUku\Stage1\Image\etoiles.png";
    let x = GetX;
    let q = 0;
    let acceleration = 0;


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


   @Initialize
   {
      LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
      LoadGraphic(imgEnemy);
	LoadGraphic(bg);
      LoadSE(tir);
      LoadSE(munch);
            SetLife(11000);
            SetTimer(60);
            SetInvincibility(60);
	SetScore(1500000);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY-100 , 60);
	CutIn(YOUMU, "Entropic sign"\""Initial explosion"\", "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) {
		Tir(GetX, GetY, 3, rand(0,360), rand_int(82,90), 60, acceleration);
	}

	if (count%50==0) {
		acceleration+=0.003;
	}

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);
            SetGraphicAngle(0, 0, 0);
            DrawGraphic(GetCenterX+q, GetCenterY+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++;
	//}
   }


   task Tir(x, y, v, angle, g, attente, accel)
   {
            let obj=Obj_Create(OBJ_SHOT);


            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, v );
            ObjShot_SetGraphic(obj, g);
            ObjShot_SetDelay  (obj, 0);
	    ObjShot_SetBombResist(obj, true);
		let counter=0;
		let changed = false;
		let couleurs = [15,12,13,11,23,22,20,19,9];
		let max = 5;

     		while(!Obj_BeDeleted(obj)) {
			if (!changed&&Obj_GetSpeed(obj)>-max) {
				Obj_SetSpeed(obj, Obj_GetSpeed(obj)-accel);
			}
			if (changed&&Obj_GetSpeed(obj)<max) {
				Obj_SetSpeed(obj, Obj_GetSpeed(obj)+accel);
			}
			if (counter==attente) {
				PlaySE(munch);
				let g2 = couleurs[g-82];
				ObjShot_SetGraphic(obj, g2);
				Obj_SetAngle(obj, rand(0,360));
	    			ObjShot_SetBombResist(obj, false);
				changed = true;
			}
			counter++;
			yield;
		}

   }


}
