#TouhouDanmakufu
#Title[Machin : "Lunarian sign : Moonsong"]
#Text[C'est grace a cette douce melodie qu'il controle les Munchers. Il les fait alors danser et tourbilloner pour distraire son adversaire. Malheureusement, les Munchers ne sont pas suffisamment gracieux...]
#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=-100;
    let obj_id = 0;
    let angle = 0;
    let bullets = [];
    let v = 0;
    let difficulties = 0;
    let lune = "script\DanMUku\Stage1\Image\lune.png";
    let bg = "script\DanMUku\Stage1\Image\etoiles.png";
    let q = 0;
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let z = 0;
    let w = 0.5;
    let d=0;

    let bonus = false;

   @Initialize
   {
      LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
      LoadGraphic(imgEnemy);
      LoadGraphic(bg);
      LoadGraphic(lune);
      LoadMusic("script\DanMUku\Stage1\Machin.mp3");
      LoadSE(tir);
      LoadSE(munch);
            SetLife(8500);
            SetTimer(55);
            SetInvincibility(100);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY - 100, 120);
            SetScore(1500000);
            CutIn(YOUMU, "Lunarian sign "\""Moonsong"\", "script\DanMUku\Stage1\Image\Machincutin.png", 0,0,121,214);
       SetEffectForZeroLife(60, 200, 2);
   }
   
 function Wait(let frames){
   loop(frames){yield;}
 }

   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);

if (GetTimer==5) {
	bonus=true;
}

if(count%100==0&&count>0)
{
PlaySE(tir);
d=GetAngleToPlayer;
loop(36)
{
Circle(GetX, GetY, 3, d, 0);
CreateShot01(GetX, GetY, 3, d+5, BLUE01, 0);
d+=10;
}
}
if(count==0)
{
angle=120;
PlaySE(tir);
loop(12)
{
Muncher(GetX, GetY, 2, angle);
angle+=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==50)
{
Concentration01(50);
}
if(count==100)
{
let i = 0;
v=2;
PlaySE(munch);
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetSpeed(obj, 3);
   }
   i++;
   v+=0.2;
}
}
if(count>100&&count<220)
{
let i = 0;
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetAngle(obj, Obj_GetAngle(obj) - 4);
   }
   i++;
}
}

if(count==300)
{
PlaySE(tir);
angle=60;
loop(12)
{
Muncher(GetX, GetY, 2, angle);
angle-=10;
}
}
if(count==350)
{
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==350)
{
Concentration01(50);
}
if(count==400)
{
let i = 0;
v=2;
PlaySE(munch);
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetSpeed(obj, 3);
   }
   i++;
   v+=0.2;
}
}
if(count>400&&count<520)
{
let i = 0;
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetAngle(obj, Obj_GetAngle(obj) + 4);
   }
   i++;
}
}

if(count==600)
{
angle=150;
PlaySE(tir);
loop(12)
{
Muncher(GetX, GetY, 2, angle);
angle+=10;
}
}
if(count==650)
{
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==650)
{
Concentration01(50);
}
if(count==700)
{
let i = 0;
PlaySE(munch);
v=2;
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetSpeed(obj, 3);
   }
   i++;
   v+=0.2;
}
}
if(count>=700&&count<820)
{
let i = 0;
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetAngle(obj, Obj_GetAngle(obj) - 3);
   }
   i++;
}
}

if(count==600)
{
angle=30;
PlaySE(tir);
loop(12)
{
Muncher(GetX, GetY, 2, angle);
angle-=10;
}
}
if(count==650)
{
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==770)
{
Concentration01(50);
}
if(count==820)
{
let i = 0;
v=2;
PlaySE(munch);
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetSpeed(obj, 3);
   }
   i++;
   v+=0.2;
}
}
if(count>=820&&count<940)
{
let i = 0;
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetAngle(obj, Obj_GetAngle(obj) + 7);
   }
   i++;
}
}

if(count==600)
{
angle=30;
PlaySE(tir);
loop(12)
{
Muncher(GetX, GetY, 2, angle);
angle+=10;
}
}
if(count==650)
{
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==890)
{
Concentration01(50);
}
if(count==940)
{
let i = 0;
v=2;
PlaySE(munch);
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetSpeed(obj, 3);
   }
   i++;
   v+=0.2;
}
}
if(count>=940&&count<1060)
{
let i = 0;
while (i < length(bullets))
{
   if (Obj_BeDeleted(bullets[i]))
   {
      bullets = erase(bullets, i);
      i--;
   }
   else
   {
      let obj = bullets[i];
      Obj_SetAngle(obj, Obj_GetAngle(obj) - 1);
   }
   i++;
}
}
if(count==1100)
{
difficulties++;
count=0;
}
if(count%300==0&&difficulties>0)
{
angle=GetAngleToPlayer;
PlaySE(tir);
loop(18)
{
Muncher(GetX, GetY, 1, angle);
angle+=20;
}
}
count++;
yield;
   }
   @Finalize
   {
	if(bonus){
		SetCommonData("S", true);
	}

      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);
     ObjShot_SetBombResist (obj_id, true);
     bullets = bullets ~ [obj_id];
     while(Obj_BeDeleted(obj_id)==false) {
             yield;
      }
}

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

     Obj_SetPosition(obj_idd, x, y);
     Obj_SetAngle(obj_idd, angle);
     Obj_SetSpeed(obj_idd, v);
     ObjShot_SetGraphic(obj_idd, BLUE01);
     ObjShot_SetDelay  (obj_idd, delay);
     Wait(50);
     PlaySE(tir);
     ObjShot_SetGraphic(obj_idd, GREEN01);
     Obj_SetSpeed(obj_idd, v/4);
     while(Obj_BeDeleted(obj_idd)==false) {
             yield;
      }
}
   @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);

            SetTexture(lune);
            SetRenderState(ALPHA);
            SetAlpha(100);
            SetGraphicRect(0, 0, 218, 213);
            SetGraphicScale(1,1);
            SetGraphicAngle(0, 0, 0);
            DrawGraphic(GetCenterX-25, GetCenterY-100);

            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetAlpha(255);
            SetTexture(imgEnemy);
            SetGraphicRect(0,0,16*1.5,16*1.5);
            DrawGraphic(GetX,GetY+z);
	q-=2;
     if(z==10){w=-0.5;}
     if(z==-10){w=0.5;}
z+=w;
	DrawText("Machin", GetClipMinX+10, GetClipMinY+15, 12, 255);
   }
}
