#TouhouDanmakufu
#Title[Machin : "Within a deep forest : Stories of flying Munchers"]
#Text[Machin est le seul membre de MU a savoir controler les Munchers, ils se deracinent et volent a son aide des qu'il les appelle. Au final, les Munchers volants ca peut etre bien pratique, mais dans un hack de SMW ca fait vraiment tache...]
#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 angle = 0;
    let bullets = [];
    let v = 0;
    let difficulties = 0;
    let bullet_id = 1;
    let d = 0;
    let obj_id=0;
    let obj = 0;
    let obj2 = 0;
    let obj3=0;
    let obj4=0;
    let q = 0;
    let arbre = "script\DanMUku\Stage1\Image\arbre.png";
    let bg = "script\DanMUku\Stage1\Image\sol.png";
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let z = 0;
    let w = 0.5;

function Bullet (id, x, y, angle)
{
PlaySE(tir);
CreateShotA(id, x, y, 0);
CreateShotA(id+1, 0, 0, 0);
CreateShotA(id+2, 0, 0, 0);
SetShotDataA(id, 0, 0, 0, 0, 0, 0, YELLOW01);
SetShotDataA(id+1, 0, 1, angle+90, 0, 0, 1, 81);
SetShotDataA(id+2, 0, 1, angle-90, 0, 0, 1, 81);
AddShot(50, id, id+1, 0);
AddShot(50, id, id+2, 0);
SetShotKillTime(id, 61);
FireShot(id);
}
   @Initialize
   {
      LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
      LoadGraphic(imgEnemy);
      LoadGraphic(arbre);
      LoadGraphic(bg);
      LoadMusic("script\DanMUku\Stage1\Machin.mp3");
            SetLife(7000);
            SetTimer(45);
            SetInvincibility(100);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY - 150, 120);
            SetScore(500000);
            CutIn(YOUMU, "Within a deep forest "\""Stories of flying Munchers"\", "script\DanMUku\Stage1\Image\Machincutin.png", 0,0,121,214);
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);
if(count==0)
{
PlaySE(tir);
Muncher(GetX, GetY, 2, 120);
Muncher(GetX, GetY, 2, 60);
obj = bullets[0];
obj2 = bullets[1];
}
if(count==30)
{
PlaySE(munch);
Bullet(1, Obj_GetX(obj), Obj_GetY(obj), 120);
Bullet(10, Obj_GetX(obj2), Obj_GetY(obj2), 60);
}
if(count==60)
{
PlaySE(munch);
Bullet(4, Obj_GetX(obj), Obj_GetY(obj), 120);
Bullet(13, Obj_GetX(obj2), Obj_GetY(obj2), 60);
}
if(count==90)
{
PlaySE(munch);
Bullet(7, Obj_GetX(obj), Obj_GetY(obj), 120);
Bullet(16, Obj_GetX(obj2), Obj_GetY(obj2), 60);
}
if(count==120)
{
PlaySE(munch);
Bullet(19, Obj_GetX(obj), Obj_GetY(obj), 120);
Bullet(22, Obj_GetX(obj2), Obj_GetY(obj2), 60);
}
if(count==150)
{
PlaySE(munch);
Bullet(25, Obj_GetX(obj), Obj_GetY(obj), 120);
Bullet(28, Obj_GetX(obj2), Obj_GetY(obj2), 60);
}
if(count==180)
{
PlaySE(munch);
Bullet(31, Obj_GetX(obj), Obj_GetY(obj), 120);
Bullet(34, Obj_GetX(obj2), Obj_GetY(obj2), 60);
}
if(count==200)
{
PlaySE(tir);
Muncher(GetX, GetY, 2, 140);
Muncher(GetX, GetY, 2, 40);
obj = bullets[2];
obj2 = bullets[3];
}
if(count==230)
{
PlaySE(munch);
Bullet(1, Obj_GetX(obj), Obj_GetY(obj), 140);
Bullet(10, Obj_GetX(obj2), Obj_GetY(obj2), 40);
}
if(count==260)
{
PlaySE(munch);
Bullet(4, Obj_GetX(obj), Obj_GetY(obj), 140);
Bullet(13, Obj_GetX(obj2), Obj_GetY(obj2), 40);
}
if(count==290)
{
PlaySE(munch);
Bullet(7, Obj_GetX(obj), Obj_GetY(obj), 140);
Bullet(16, Obj_GetX(obj2), Obj_GetY(obj2), 40);
}
if(count==320)
{
PlaySE(munch);
Bullet(19, Obj_GetX(obj), Obj_GetY(obj), 140);
Bullet(22, Obj_GetX(obj2), Obj_GetY(obj2), 40);
}
if(count==350)
{
PlaySE(munch);
Bullet(25, Obj_GetX(obj), Obj_GetY(obj), 140);
Bullet(28, Obj_GetX(obj2), Obj_GetY(obj2), 40);
}
if(count==380)
{
PlaySE(munch);
Bullet(31, Obj_GetX(obj), Obj_GetY(obj), 140);
Bullet(34, Obj_GetX(obj2), Obj_GetY(obj2), 40);
}
if(count==215)
{
PlaySE(tir);
Muncher(GetX, GetY, 2, 100);
Muncher(GetX, GetY, 2, 80);
obj3 = bullets[4];
obj4 = bullets[5];
}
if(count==245)
{
PlaySE(munch);
Bullet(37, Obj_GetX(obj3), Obj_GetY(obj3), 100);
Bullet(40, Obj_GetX(obj4), Obj_GetY(obj4), 80);
}
if(count==275)
{
PlaySE(munch);
Bullet(43, Obj_GetX(obj3), Obj_GetY(obj3), 100);
Bullet(46, Obj_GetX(obj4), Obj_GetY(obj4), 80);
}
if(count==305)
{
PlaySE(munch);
Bullet(49, Obj_GetX(obj3), Obj_GetY(obj3), 100);
Bullet(52, Obj_GetX(obj4), Obj_GetY(obj4), 80);
}
if(count==335)
{
PlaySE(munch);
Bullet(55, Obj_GetX(obj3), Obj_GetY(obj3), 100);
Bullet(58, Obj_GetX(obj4), Obj_GetY(obj4), 80);
}
if(count==365)
{
PlaySE(munch);
Bullet(61, Obj_GetX(obj3), Obj_GetY(obj3), 100);
Bullet(64, Obj_GetX(obj4), Obj_GetY(obj4), 80);
}
if(count==395)
{
PlaySE(munch);
Bullet(67, Obj_GetX(obj3), Obj_GetY(obj3), 100);
Bullet(70, Obj_GetX(obj4), Obj_GetY(obj4), 80);
}
if(difficulties==1&&count%210==0)
{
angle=180;
PlaySE(tir);
loop(11)
{
CreateShot01(GetX, GetY, 1, angle, GREEN03, 0);
CreateShot01(GetX, GetY, 2, angle+180, GREEN01, 0);
CreateShot01(GetX, GetY, 2, angle+189, GREEN01, 0);
angle+=18;
}
}
if(count==420)
{
difficulties = 1;
bullets=[];
count=-1;
}
count++;
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(arbre);
            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);
            SetGraphicRect(0,0,16*1.5,16*1.5);
            DrawGraphic(GetX,GetY+z);

	q-=1;
     if(z==10){w=-0.5;}
     if(z==-10){w=0.5;}
z+=w;
	DrawText("Machin", GetClipMinX+10, GetClipMinY+15, 12, 255);

   }

   @Finalize
   {
	loop(5)
	{
	CreateItem(ITEM_SCORE, rand(GetX-20, GetX+20), rand(GetY-20, GetY+20));  
	}
	if (GotSpellCardBonus) {
		SetCommonData("U", 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);
     bullets = bullets ~ [obj_id];
     while(Obj_BeDeleted(obj_id)==false) {
             yield;
      }
}

}
