#TouhouDanmakufu
#Title[Machin et J64 : "Stories of flying Munchers 2 : Starry Boogaloo"]
#Text[La suite de Histoires de Munchers Volants ft. J64 ! Les munchers volent toujours de la meme maniere, pensez a une maniere de vous y deplacer et faites-le a chaque fois que J64 attaque. Je me demande s'il y a un moyen d'ignorer les munchers...]
#Image[]
#BGM[script\DanMUku\Stage6\Stage6.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 munch = "script\DanMUku\Stage1\Son\muncher.wav";
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let arbre = "script\DanMUku\Stage1\Image\arbre.png";
    let bg = "script\DanMUku\Stage1\Image\sol.png";
    let z = 0;
    let w = 0.5;
    let q =0;
    let angle = GetAngleToPlayer;
    let release = false;
   @Initialize
   {
      LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
      LoadGraphic(imgEnemy);
      LoadGraphic(arbre);
      LoadGraphic(bg);
      LoadSE(tir);
      LoadSE(munch);
            SetLife(11000);
            SetTimer(60);
            SetInvincibility(60);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY - 20, 120);
	CreateEnemyFromScript("J64", GetCenterX+100, GetCenterY-100, 0, 0, 0);
	SetScore(2500000);
            CutIn(YOUMU, ""\""Stories of flying Munchers 2 : Starry Boogaloo"\", "script\DanMUku\Stage1\Image\Machincutin.png", 0,0,121,214);
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);

	if (count==30) {
		let a = 90;
		loop(8) {
			Muncher(GetX, GetY, 1, a);
			a+=360/8;
		}
	}

	if (count==510) {
		let a = 105;
		loop(8) {
			Muncher(GetX, GetY, 1, a);
			a+=360/8;
		}
	}

	if (count==990) {
		let a = 120;
		loop(8) {
			Muncher(GetX, GetY, 1, a);
			a+=360/8;
		}
	}

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);

            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 et J64", GetClipMinX+10, GetClipMinY+15, 12, 255);
   }


task Muncher(x, y, v, angle) {
     let obj_id=Obj_Create(OBJ_SHOT);

		PlaySE(munch);
     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);
	let count = 80;
     while(Obj_BeDeleted(obj_id)==false) {
		if (count%120==0){
			Bullet(Obj_GetX(obj_id), Obj_GetY(obj_id), v, angle);
		}
		count++;
             yield;
      }
}

task Bullet(x, y, v, angle) {
     let obj_id=Obj_Create(OBJ_SHOT);

     Obj_SetPosition(obj_id, x, y);
     Obj_SetAngle(obj_id, angle);
     Obj_SetSpeed(obj_id, 0);
     ObjShot_SetGraphic(obj_id, YELLOW01);
     ObjShot_SetDelay  (obj_id, 0);
     ObjShot_SetBombResist(obj_id, true);
	let count = 1;
     while(Obj_BeDeleted(obj_id)==false) {
		if (count%120==0){
				PlaySE(munch);
			CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), v, angle-90, 81, 0);
			CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), v, angle+90, 81, 0);
		}
		count++;
             yield;
      }
}

}

script_enemy J64
{    
    let imgEnemy2="script\DanMUku\Stage4\Image\j64.png";
    let count=-100;
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let g = 53;
   @Initialize
   {
      LoadUserShotData("lib\MUtir\MUtir.txt");
      LoadGraphic(imgEnemy2);
		SetLife(1);
            SetInvincibility(60);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX+150, GetCenterY - 200, 120);
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);
	SetDamageRateEx(0,0,100,100);
	

	if (count>0&&count%150==100) {
		g=53;
		if (GetX>GetCenterX) {
			SetMovePosition02(GetCenterX-150, GetCenterY - 200, 50);
		}
		else {
			SetMovePosition02(GetCenterX+150, GetCenterY - 200, 50);
		}
	}

	if (count>0&&count%150>100&&count%8==0) {
		PlaySE(tir);
		CreateShot01(GetX, GetY, 4, GetAngleToPlayer, g, 0);
		g++;
	}

count++;
yield;
   }
   @Finalize
   {
      DeleteGraphic(imgEnemy2);
   }

   @DrawLoop
   {
            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(imgEnemy2);
            SetGraphicRect(0,0,36,43);
            DrawGraphic(GetX,GetY);
   }

}
