#TouhouDanmakufu
#Title[Luidi : "Broken chain"]
#Text[Ici, Luidi partitionne le ring puis la "casse" pour attaquer. Prevoyez la trajectoire des kunais pour vous retrouver avec le plus grand espace possible. Le nombre de chaines augmentent au fur et a mesure. Allez ! Brisez-moi donc ces verrous-psyche et faites-lui cracher ce qu'il sait !]
#Image[]
#BGM[script\DanMUku\Stage3\Luidi.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\Stage3\Image\luidi.png";
    let count = -50;
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let a = 0;
    let bullets = [];
    let id = 1;
    let t = 0;
    let dif = 0 ;
    let angle =0;
    let q=0;
    let bg = "script\DanMUku\Stage3\Image\vitrail.png";

   @Initialize
   {
            LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
            LoadGraphic(imgEnemy);
	LoadGraphic(bg);
            SetLife(12000);
            SetTimer(95);
            SetInvincibility(200);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY-100, 50);   
            SetScore(2500000);
            SetEffectForZeroLife(60,200,2);
            CutIn(YOUMU, "Broken chain", "script\DanMUku\Stage3\Image\luidicutin.png" , 0,0,99,200);               
   }
   
   @MainLoop
   {
        SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);

if(count%300==0&&count>0)
{
SetMovePositionRandom01(50, 50, 2, GetClipMinX+10, GetClipMinY+50, GetClipMaxX-10, GetCenterY+50);
}
if(count==100)
{
a=GetAngleToPlayer;
PlaySE(tir);
loop(3+dif)
{
Bouncing_Bullet(GetX, GetY, 4, a, 0, 28);
a+=360/(3+dif);
}
}
if(count%5==0)
{
let i = 0;
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      CreateShotA(id, Obj_GetX(obj), Obj_GetY(obj), 15);
      SetShotDataA(id, 0, 0, Obj_GetAngle(obj), 0, 0, 0, PURPLE01);
      SetShotDataA(id, 400-t, 0, Obj_GetAngle(obj)+rand_int(-1,1)*90, 0, 0.003, 1, YELLOW01);
       FireShot(id);
      t+=5/(3+dif);
   }
   i++;
}
}
if(count==450)
{
Concentration01(50);
}
if(count==500)
{
PlaySE(munch);
}
if(count==700)
{
count=0;
t=0;
id++;
dif++;
}
count++;
yield;
   }
   @Finalize
   {
      DeleteGraphic(imgEnemy);
   }
   
   @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);

            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(imgEnemy);
            SetGraphicAngle (0, 0, 0);
            SetGraphicRect(0, 0, 33, 33);
            DrawGraphic(GetX,GetY);
	q+=1;
	DrawText("Luidi", GetClipMinX+10, GetClipMinY+15, 12, 255);
   }

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

            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, bullet);
            ObjShot_SetDelay  (obj, delay);
            ObjShot_SetBombResist (obj, true);
	bullets = bullets~[obj];
	let counter = 0;

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

                    if(Obj_GetX(obj)>GetClipMaxX&&counter<=1)
         {

                          Obj_SetAngle(obj, 180-Obj_GetAngle(obj) );
                          Obj_SetX(obj,  Obj_GetX(obj) - 0.1);
	counter++;
                  }

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

                    if(Obj_GetY(obj)>GetClipMaxY&&counter<=1)
         {
	        Obj_SetAngle(obj, -Obj_GetAngle(obj) );
                          Obj_SetY(obj,  Obj_GetY(obj) - 0.1);
	counter++;
                    }
         yield;
            }
   }

}
