
#Title[幻月・通常弾幕3]
#Text[幻月・通常弾幕3]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
   let imgBOSS = csd~"img\dot_gengetu.png";
   let shotData = csd ~ "data_usershot.txt";
  let effect = csd ~ "img\circle.png";
  let vanish = false;

   @Initialize{
 SetCommonDataEx("","bg",8);
           SetLife(4000);
      SetDamageRate(100,0);
     /*      SetTimer(30);  */
           SetInvincibility(120);
         sgr(0,0);
/*SetMovePosition03(GetCenterX,GetClipMinY+120,20,10);*/
        SetAlpha(255);
           LoadGraphic(imgBOSS);
    LoadGraphic(effect);
          LoadUserShotData(shotData);
  Circle2(60);
           TMain;
    }

   @MainLoop{
    if(OnEvent){break;}
     if(!OnBomb && !vanish){
      SetCollisionA(GetX, GetY, 24);
      SetCollisionB(GetX, GetY, 18);
     }

         yield;
       }

   @DrawLoop{
         SetTexture(imgBOSS);  
        DrawGraphic(GetX,GetY);
     }

    @Finalize{
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
     }
 
     task TMain{
  yield;
   SetX(cx);
   SetY(miny+100);
  SetTimer(55);
   SetInvincibility(120);
          wait(90);
        Shot;
    loop{
   if(OnBomb && !vanish){SetAlpha(0);}
   else if(!OnBomb && !vanish){SetAlpha(255);}
    wait(1);
      }
    }

   task Shot{
 sgr(3,2);
   let color = 174;
  let delay = 10;
  let v = [4,6,4,2];
  let i = 0;
  loop{
 let base = rand(-180,180);
 let r = rand(-32,32);
  let r2 = rand(-32,32);
    ascent(b in 0..2){
  ascent(a in 0..18){
  let x = GetX+r+offsetX(4,base+20*a+90*(-1)^b);
  let y = GetY+r2+offsetY(4,base+20*a+90*(-1)^b);
  CreateShot01(x,y,v[i],base+20*a,color,delay);
      }
     }
  i++;
  if(i > 3){i = 0;}
  PlaySE(seshot1);
   wait(10);
       }
  } 

    function Move{
    ascent(a in 0..21){
     SetGraphicScale(1-a*0.05,1-a*0.05);
   if(a >= 15){vanish = true;}
      wait(1);
        }
   SetX(rand(minx+64,maxx-64));
   SetY(GetY);
     ascent(a in 0..21){
     SetGraphicScale(a*0.05,a*0.05);
   if(a >= 15){vanish = false;}
      wait(1);
        }
    }

    function offsetX(radius,angle){
           return radius * cos(angle);
     }

        function offsetY(radius,angle){
            return radius * sin(angle);
     }           

       function move(f){
          SetMovePosition02(rand(GetClipMinX+60,GetClipMaxX-60),GetY+rand(-20,20),f);
     }
            
        function sc(r,g,b){
             SetShotColor(r,g,b);
     }

  function sgr(a,b){SetGraphicRect(a*128,b*128,(a+1)*128,(b+1)*128);}

       function wait(w){
                loop(w){yield;}
       }
}