
#Title[幻月・通常弾幕2]
#Text[幻月・通常弾幕2]
#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;
  SetY(miny+120);
   Move;
  SetTimer(55);
   SetInvincibility(120);
          wait(90);
        Shot;
    loop{
   if(OnBomb && !vanish){SetAlpha(0);}
   else if(!OnBomb && !vanish){SetAlpha(255);}
    wait(1);
      }
    }

   task Shot{
  loop{
  let color = 41; let delay = 20;
 let base = 180+atan2(GetY-25-GetPlayerY,GetX+5-GetPlayerX);
  sgr(3,2);
    ascent(b in 0..4){
  let dd = rand(-8,8);
    ascent(c in 0..15){
    ascent(a in 0..2){
  let v = 1+0.3*c;
  let x = GetX+5; let y = GetY-25;
  let t = 0;
  loop(b+1){
   let angle = base+(25+30*t-dd)*a-(25+30*t-dd)/2;
   CreateShot01(x,y,v,angle,color,delay);
  t++;
       }
     }
    }
  PlaySE(seshot3);
  wait(20);
     }
  loop(15){
 let base = 180+atan2(GetY-25-GetPlayerY,GetX+5-GetPlayerX);
  ascent(v in 0..9){
   CreateShot01(GetX+5,GetY-25,1.5+v*0.75,base,38,20);
       }
    PlaySE(seshot3);
      wait(5);
        }
  wait(30);
   sgr(0,0);
     Move;
    sgr(3,2);
   Concentration01(60);
   wait(60);
  let v = 5;
  let base = 180+atan2(GetY-25-GetPlayerY,GetX+5-GetPlayerX);
  ascent(way in 1..17){
  ascent(a in 0..way){
   let angle = base - (way-1)/2*10+10*a;
   CreateShot01(GetX+5,GetY-25,v,angle,8,0);
    }
     PlaySE(seshot4);
     wait(4);
       }
  wait(30);
   sgr(0,0);
     Move;
   wait(30);
    }
  } 

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