#TouhouDanmakufu
#Title[Boss Luidi NSC01]
#Text[1ere attaque du Boss du stage 3]
#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 a =0;
    let d = 0;
let dif = 0;

   @Initialize
   {
            LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
            LoadGraphic(imgEnemy);
            SetLife(6000);
            SetTimer(40);
            SetInvincibility(100);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY-100, 50);           
   }
   
   @MainLoop
   {
        SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);
if(count%150==0)
{ 
a=GetAngleToPlayer;
PlaySE(tir);
loop(36)
{
Bouncing_Bullet(GetX, GetY, 2, a, 0, 28);
a+=10;
}
}
if(count==100||count==300||count==600)
{
SetMovePositionRandom01(50, 50, 2, GetClipMinX+10, GetClipMinY+50, GetClipMaxX-10, GetCenterY+50);
}
if(count==200&&dif==0)
{
a= GetAngleToPlayer;
loop(10)
{
PlaySE(tir);
loop(5)
{
Bouncing_Bullet(GetX+50*cos(-a+45), GetY+50*sin(-a+45), 2, -a+45, d, 28);
CreateShot01(GetX+50*cos(a-45), GetY+50*sin(a-45), 2, a-45, 35, d);
d+=5;
}
d-=20;
a+=9;
}
}
if(count==400&&dif==0)
{
a= 110;
loop(10)
{
PlaySE(tir);
d-=20;
loop(5)
{
Bouncing_Bullet(GetX+50*cos(-a+45), GetY+50*sin(-a+45), 2, -a+45, d, 28);
CreateShot01(GetX+50*cos(a-45), GetY+50*sin(a-45), 2, a-45, 35, d);
d+=5;
}
a+=9;
}
}
if(count==500&&dif==0)
{
a= 50;
loop(10)
{
PlaySE(tir);
d-=20;
loop(5)
{
Bouncing_Bullet(GetX+50*cos(-a+45), GetY+50*sin(-a+45), 2, -a+45, d, 28);
CreateShot01(GetX+50*cos(a-45), GetY+50*sin(a-45), 2, a-45, 35, d);
d+=5;
}
a+=9;
}
}
if(count%200==0&&dif>0)
{
a= rand(20, 160);
loop(10)
{
PlaySE(tir);
d-=20;
loop(5)
{
Bouncing_Bullet(GetX+50*cos(-a+45), GetY+50*sin(-a+45), 2, -a+45, d, 28);
CreateShot01(GetX+50*cos(a-45), GetY+50*sin(a-45), 2, a-45, 35,d);
d+=5;
}
a+=9;
}
}
if(count%100==0&&dif>1)
{
a= rand(20, 160);
loop(10)
{
PlaySE(tir);
d-=20;
loop(5)
{
Bouncing_Bullet(GetX+50*cos(-a+45), GetY+50*sin(-a+45), 2, -a+45, d, 28);
CreateShot01(GetX+50*cos(a-45), GetY+50*sin(a-45), 2, a-45, 35, d);
d+=5;
}
a+=9;
}
}
if(count==600)
{
count=0;
dif+=1;
}
d=0;
count++;
yield;
   }
   @Finalize
   {
      DeleteGraphic(imgEnemy);
   }
   
   @DrawLoop
   {
            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(imgEnemy);
            SetGraphicAngle (0, 0, 0);
            SetGraphicRect(0, 0, 33, 33);
            DrawGraphic(GetX,GetY);
	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);
      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, 30);
            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, 30);
            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, 30);
            counter++;
                    }

         yield;
            }
   }
}
