#TouhouDanmakufu
#Title[NSC01 Machin]
#Text[Première Non-spell de Machin]
#Image[]
#BGM[script\DanMUku\Stage1\Machin.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\Stage1\Image\Machin.png";
    let count=-200;
    let bullets = [];
    let a = 0;
    let obj_id=0;
    let circle =  [];
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let z = 0;
    let w = 0.5;
   @Initialize
   {
      LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
      LoadGraphic(imgEnemy);
      LoadMusic("script\DanMUku\Stage1\Machin.mp3");
      LoadSE(tir);
      LoadSE(munch);
            SetLife(4000);
            SetTimer(30);
            SetInvincibility(60);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY - 100, 120);
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);
if(OnEvent==false)
{
if(count==-100)
{
a=0;
PlaySE(tir);
loop(36)
{
CreateShot01(GetX, GetY, 1, a, BLUE01, 0);
Circle(GetX, GetY, 1, a+5, 0);
a+=10;
}
}
if(count==0)
{
let i = 0;
PlaySE(tir);
while (i < length(circle))
{
   if (Obj_BeDeleted(circle[i]))
   {
      circle = erase(circle, i);
      i--;
   }
   else
   {
      let obj = circle[i];
      Obj_SetSpeed(obj, 0.5);
      ObjShot_SetGraphic(obj, GREEN01);
   }
   i++;
}
}
if(count==0)
{
a=GetAngleToPlayer;
PlaySE(tir);
loop(36)
{
Muncher(GetX, GetY, 2, a);
a+=10;
}
}
if(count==50)
{
let i = 0;
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetSpeed(obj, 0);
   }
   i++;
}
}
if(count==100)
{
a=0;
PlaySE(tir);
loop(36)
{
CreateShot01(GetX, GetY, 1, a, BLUE01, 0);
Circle(GetX, GetY, 1, a+5, 0);
a+=10;
}
let i = 0;
PlaySE(munch);
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetSpeed(obj, 2);
      Obj_SetAngle(obj, atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj)));
   }
   i++;
}
}
if(count==200)
{
let i = 0;
PlaySE(tir);
while (i < length(circle))
{
   if (Obj_BeDeleted(circle[i]))
   {
      circle = erase(circle, i);
      i--;
   }
   else
   {
      let obj = circle[i];
      Obj_SetSpeed(obj, 0.5);
      ObjShot_SetGraphic(obj, GREEN01);
   }
   i++;
}
count=-101;
}
count++;
yield;
}
   }
   @Finalize
   {
      DeleteGraphic(imgEnemy);
   }
   
   task Muncher(x, y, v, angle) {
     obj_id=Obj_Create(OBJ_SHOT);

     Obj_SetPosition(obj_id, x, y);
     Obj_SetAngle(obj_id, angle);
     Obj_SetSpeed(obj_id, v);
     ObjShot_SetGraphic(obj_id, 81);
     ObjShot_SetDelay  (obj_id, 0);
     bullets = bullets ~ [obj_id];
     while(Obj_BeDeleted(obj_id)==false) {
             yield;
      }
}

   task Circle(x, y, v, angle, delay) {
     obj_id=Obj_Create(OBJ_SHOT);

     Obj_SetPosition(obj_id, x, y);
     Obj_SetAngle(obj_id, angle);
     Obj_SetSpeed(obj_id, v);
     ObjShot_SetGraphic(obj_id, BLUE01);
     ObjShot_SetDelay  (obj_id, delay);
     circle = circle ~ [obj_id];
     while(Obj_BeDeleted(obj_id)==false) {
             yield;
      }
}
   @DrawLoop
   {
            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(imgEnemy);
            SetGraphicRect(0,0,16*1.5,16*1.5);
            DrawGraphic(GetX,GetY+z);
     if(z==10){w=-0.5;}
     if(z==-10){w=0.5;}
z+=w;
	DrawText("Machin", GetClipMinX+10, GetClipMinY+15, 12, 255);
   }

}
