
#Title[閉符　「クロージング・サークル」]
#Text[夢月・スペル5]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
   let name        = " 閉符　「クロージング・サークル」";
   let imgBOSS = csd~"img\dot_mugetu.png";
   let shotData = csd ~ "data_usershot.txt";
  let effect = csd ~ "img\circle.png"; 

   @Initialize{
  SetCommonDataEx("","bg",4);
     CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(2500000);
           SetLife(600);
      SetDamageRate(20,0);
           SetTimer(60);
           SetInvincibility(120);
         sgr(0,0);
         SetMovePosition03(GetCenterX,GetClipMinY+100,20,5);
        SetAlpha(255);
           LoadGraphic(imgBOSS);
    LoadGraphic(effect);
          LoadUserShotData(shotData);
    Circle2(60);
           TMain;
    }

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

         yield;
       }

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

    @Finalize{
  SetCommonDataEx("","bg",3);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
  loop(64){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,150)); 
       }   
     }
 
     task TMain{
          wait(90);
  SetShotAutoDeleteClip(200,200,200,200);
  SetMovePosition02(cx,cy,10);
        Shot;
        Count;
    loop{
   if(OnBomb){
   SetAlpha(0);
   SetDamageRate(0,0);}
     else{
    SetAlpha(255);
   SetDamageRate(20,0);}
    wait(1);
      }
    }

   task Shot{
  let way = 180;
  let v = 1.5;  let v2 = 2.5;
  let w = 2;
 let ori = 90;
 loop{
  ascent(a in 0..11){
  let angle = ori+(50+4*a)*a;
  Shot1(angle,45);
   wait(30);
      }
  Delete(330+120);
   ascent(a in 0..11){
  let angle = ori-(40+0.3*a)*a;
  Shot2(250+10*a,angle,42);
   wait(30);
      }
  wait(120);
   ori = GetAngleToPlayer;
   }
  
    task Shot1(base,color){
     ascent(a in 0..way/2){
     let angle = base + 90 + 360/way*a;
   CreateShot01(cx,cy,v,angle,color,0);
         }
  PlaySE(seshot1);
  wait(w);
    ascent(a in 0..way/4+1){
  let angle = base+90-360/way*a;
  let angle2 = base-90+360/way*a;
  let x = cx+offsetX(v*w*(a+1),angle);
  let y = cy+offsetY(v*w*(a+1),angle);
  let x2 = cx+offsetX(v*w*(a+1),angle2);
  let y2 = cy+offsetY(v*w*(a+1),angle2);
  CreateShot01(x,y,v,angle,color,0);
  CreateShot01(x2,y2,v,angle2,color,0);
  PlaySE(seshot1);
   wait(w);
       }
      }
   task Shot2(radius,base,color){
/*  let radius = 300;*/
     ascent(a in 0..way/2){
   let angle = base + 90 + 360/way*a;
 let x = cx+offsetX(radius,angle);
 let y = cy+offsetY(radius,angle);
   CreateShot01(x,y,v2,180+angle,color,0);
         }
  PlaySE(seshot1);
  wait(w);
    ascent(a in 0..way/4+1){
  let angle = base+90-360/way*a;
  let angle2 = base-90+360/way*a;
  let x = cx+offsetX(radius-v2*w*(a+1),angle);
  let y = cy+offsetY(radius-v2*w*(a+1),angle);
  let x2 = cx+offsetX(radius-v2*w*(a+1),angle2);
  let y2 = cy+offsetY(radius-v2*w*(a+1),angle2);
  CreateShot01(x,y,v2,180+angle,color,0);
  CreateShot01(x2,y2,v2,180+angle2,color,0);
  PlaySE(seshot1);
   wait(w);
       }
      }
    }

  task Delete(frame){
    loop(frame){
      DeleteEnemyShotImmediatelyInCircle(ALL,GetX,GetY,8);
       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;}
       }
}