#TouhouDanmakufu
#Title[Madi : "Yellow Cards : Unexpected effect"]
#Text[Tenir jusqu'a la victoire.]
#Image[]
#BGM[script\DanMUku\Stage5\Stage5.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\Stage5\Image\fyn.png";
    let bg = "script\DanMUku\Stage5\Image\abstrait.png";
    let q=0;
    let count=-60;
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let z = 0;
    let w = 0.5;

   @Initialize
   {
            LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
            LoadGraphic(imgEnemy);
	    LoadGraphic(bg);
	    LoadSE(munch);
	    LoadSE(tir);
            SetLife(2000);
            SetTimer(25);
            SetInvincibility(160);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY-100, 120);  
	    SetScore(500000);
            CutIn(YOUMU, "Yellow Cards"\""Unexpected effect"\", "script\DanMUku\Stage5\Image\fyncutin.png" , 0,0,121,214);     
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);

	if (count%80==0&&count>0) {
		let angle=rand_int(0,360);
		loop(7){
			Lanceur(GetX, GetY, angle, rand(1,3), 87, rand(20, 50), rand(4,8));
			angle+=360/7;
		}
	}

	if (count%100==0) {
		SetMovePositionRandom01(50, 50, 2, GetClipMinX+20, GetClipMinY+20, GetClipMaxX-20, GetCenterY-10);
	}

	
	count++;
	yield;
   }
   @Finalize
   {
	if(GotSpellCardBonus){
		SetCommonData("madi", GetCommonData("madi")+1);
	}
      DeleteGraphic(imgEnemy);
   }
   
   @DrawLoop
   {
	SetColor(255,255,0);
	SetRenderState(ALPHA);
            SetAlpha(255);
            SetTexture(bg);
	    SetGraphicAngle(0, 0, 0);
            SetGraphicRect(-q, q, 640-q, 480+q);
            DrawGraphic(GetCenterX,GetCenterY);
		q+=1;

            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetAlpha(255);
            SetTexture(imgEnemy);
            SetGraphicRect(78, 0, 117, 60);
            DrawGraphic(GetX,GetY);
	DrawText("Madi ?", GetClipMinX+10, GetClipMinY+15, 12, 255);
   }

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

   task Lanceur(x, y, a, v, graphic, waiting, n) {
	let obj=Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, a);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, graphic);
	    ObjShot_SetBombResist(obj, true);
	PlaySE(tir);

	Wait(waiting);
	let angle=rand_int(0,360);
	loop(n){
		Carte_Jaune(Obj_GetX(obj), Obj_GetY(obj), 3, angle, 10);
		angle+=360/n;
	}
	Obj_Delete(obj);
	PlaySE(munch);
   }


   task Carte_Jaune(x, y, v, angle, delay)
   {
            let obj=Obj_Create(OBJ_SHOT);

            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, 144);
            ObjShot_SetDelay  (obj, delay);
      let counter=0;

            while(Obj_BeDeleted(obj)==false)
      {
                    if(Obj_GetX(obj)<GetClipMinX&&counter==0)
         {
                          Obj_SetAngle(obj,  180-Obj_GetAngle(obj) );
                          Obj_SetX(obj,  Obj_GetX(obj) + 0.1);
	        ObjShot_SetGraphic(obj, 50);
            counter++;
                    }

                    if(Obj_GetX(obj)>GetClipMaxX&&counter==0)
         {
                          Obj_SetAngle(obj,  180-Obj_GetAngle(obj) );

                          Obj_SetX(obj,  Obj_GetX(obj) - 0.1);
	        ObjShot_SetGraphic(obj, 50);
            counter++;
                    }

                    if(Obj_GetY(obj)<GetClipMinY&&counter==0)
         {
	        Obj_SetAngle(obj, -Obj_GetAngle(obj) );
                          Obj_SetY(obj,  Obj_GetY(obj) + 0.1);
	        ObjShot_SetGraphic(obj, 50);
            counter++;
                    }

         yield;
            }
   }



}
