#TouhouDanmakufu
#Title[Boss FdRstar NSC01]
#Text[1ere Non Spell-Card du Boss du stage 4]
#Image[]
#BGM[script\DanMUku\Stage4\FdRstar.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\Stage4\Image\fdrstar.png";
    let count = -50;
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let a=0;
    let b=55;
    let x=GetX;
    let c=0;
    let angle=0;

 function Wait(let frames){
   loop(frames){yield;}
 }

   @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%10==0){
	if(a==0){a=55;b=112;c=0;}
	else if(a==55&&c==0){a=112;b=168;}
	else if(a==55&&c==1){a=0;b=55;}
	else{a=55;b=112;c=1;}
}
if(count%600==0&&count>0)
{
SetMovePositionRandom01(50, 50, 2, GetClipMinX+10, GetClipMinY+50, GetClipMaxX-10, GetCenterY);
}

if(count%600==60&&count>0)
{
	PlaySE(tir);
	loop(3){
		Butterfly(GetX, GetY, 2, 0.1, angle, 2, 10, 60, 1, 240);
		angle+=120;
	}
}
if(count%600==120&&count>0)
{
	PlaySE(tir);
	loop(3){
		Butterfly(GetX, GetY, 2, 0.1, angle, -2, 10, 62, 1, 240);
		angle+=120;
	}
}
count++;
yield;
   }
   @Finalize
   {
      DeleteGraphic(imgEnemy);
   }
   
   @DrawLoop
   {
	if(x>GetX){
		SetGraphicAngle(180,0,0);
	}
	if(x<GetX){
		SetGraphicAngle(0,0,0);
	}
      x=GetX;
            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(imgEnemy);
            SetGraphicRect(a, 0, b, 64);
            DrawGraphic(GetX,GetY);

	DrawText("FdRstar", GetClipMinX+10, GetClipMinY+15, 12, 255);
   }

    task Butterfly(x, y, v, acc, angle, angv, delay, bullet, type, time)
   {
            let obj=Obj_Create(OBJ_SHOT);

            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, 0);
            ObjShot_SetGraphic(obj, bullet);
            ObjShot_SetDelay  (obj, delay);
            ObjShot_SetBombResist(obj, true);

		Papillon(obj, 0.1, 3, type, time);
            while(Obj_BeDeleted(obj)==false)
      {
	Obj_SetAngle(obj, Obj_GetAngle(obj)+angv);
	if(Obj_GetSpeed(obj)<v){
		Obj_SetSpeed(obj, Obj_GetSpeed(obj)+acc);
	}
         yield;
            }
   }

	task Papillon(obj, acc, vm, type, time)
     {
	let d=vm/7;
	Wait(time);
	if(type==1){
		PlaySE(munch);
		loop(6){
			Butterfly(Obj_GetX(obj), Obj_GetY(obj), d, acc, Obj_GetAngle(obj), 0, 10, 61, 2, 120);
			d+=vm/7;
		}}
	if(type==2){
		PlaySE(munch);
		loop(6){
			CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, atan2(-Obj_GetY(obj)+GetPlayerY, -Obj_GetX(obj)+GetPlayerX), acc, d*1.5, 65, 10);
			d+=vm/7;
		}}
	Obj_Delete(obj);
}
}
