
#Title[幽香・通常弾幕1]
#Text[幽香・通常弾幕1]
#Player[FREE]
#ScriptVersion[2]

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

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

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

         yield;
       }

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

    @Finalize{
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
     }
 
     task TMain{
  yield;
  SpinMotion(35);
  SetX(cx);
   SetY(miny+120);
      ascent(a in 0..18){
      SetAlpha(15*a);
   if(a >= 15){vanish = false;}
   wait(2);
      }
 CreateEventFromScript("Talk");
  while(OnEvent){ wait(1);}
  Circle2(60);
  SetTimer(48);
   SetInvincibility(120);
          wait(90);
        Shot;
    loop{
   if(OnBomb){SetDamageRate(10,10);}
     else{SetDamageRate(100,0);}
    wait(1);
      }
    }

   task Shot{
 Shot1;
  wait(60);
  SpinMotion(35);
   Move;
   wait(30);
 let prefer = 1;
 loop{
   let id = rand_int(1,6);
 while(id == prefer){id = rand_int(1,6);}
  alternative(id)
   case(1){Shot1;}
   case(2){Shot2;}
    case(3){Shot3;}
   case(4){Shot4;}
  case(5){Shot5;}
   case(6){Shot6;}
  wait(60);
  SpinMotion(35);
   Move;
   wait(30);
  prefer = id;
  }

    function Shot1{
 SpinMotion(28);
    let way = 48;
   let delay = 10;
  let accel = -0.1;
  let color = 155;
     ascent(b in 0..2){
    ascent(a in 0..way){
    let angle =  GetAngleToPlayer+180/way+360/way*a;
   let v = 3+b;
    let x = GetX;
      let y = GetY;
    CreateShotA(0,x,y,delay); 
    SetShotDataA(0,0,v,angle,0,accel,0,color);
    SetShotDataA(0,v*10+10,v,angle+90*(-1)^a,0,0,0,color);
     FireShot(0);
          }
      PlaySE(seshot4);
    wait(15);
      }
       }
  function Shot2{
 SpinMotion(21);
    let way = 40;
   let delay = 10;
  let color = 16;
  let base = GetAngleToPlayer;
   ascent(b in 0..2){
    ascent(a in 0..way/2){
    let angle =  base+90-360/way*a;
  let ratio = ((offsetX(30,180-360/way*a))^2+(offsetY(120,180-360/way*a))^2)^0.5;
   let v = ratio/45;
    let accel = 0;
    let x = GetX;
      let y = GetY;
    CreateShotA(0,x,y,delay+60*b); 
    SetShotDataA(0,0,v+4*b,angle+5*b,0,accel,v,color);
     FireShot(0);
  CreateShot01(x,y,v+4*b,angle+5*b,color,delay+60*b);
   }
          }
  PlaySE(seshot4);
       }
 function Shot3{
 SpinMotion(24);
    let way = 8*25;
   let delay = 10;
  let color = 3;
  let base = GetAngleToPlayer;
   loop(8){
   loop(way/8){
    let angle = rand(-180,180);
   let v = rand(0.1,3);
    let accel = 0.01;
    let x = GetX;
      let y = GetY;
     GravityShot( x, y,v, angle,accel,90, color, delay );
          }
    PlaySE(seshot4);
    wait(5);
          }
       }

   function Shot4{
 let id = rand_int(0,1);
  let ddd = 16;
    let way = 18;
   let delay = 30;
  let color = 174;
  let v = 6;
    ascent(a in 0..way*4){
  ascent(b in 0..2){
   ascent(c in 0..2){
    let angle =  (-1)^id*ddd*a+180*b;
    let x = GetX+offsetX(8,angle-90+180*c);
      let y = GetY+offsetY(8,angle-90+180*c);
  CreateShot01(x,y,v,angle,color,delay);
          }
      }
   PlaySE(seshot1);
    wait(2);
      }
  ascent(a in 0..36){
  CreateShot01(GetX,GetY,v+0.2,GetAngleToPlayer+10*a+5,155,30);
   }
    PlaySE(seshot4);
 /* wait(60);
  let v = 5;
    ascent(a in 0..way*5){
  ascent(b in 0..2){
    ascent(c in 0..2){
    let angle =  -ddd*a+180*b;
    let x = GetX+offsetX(5,angle-90+180*c);
      let y = GetY+offsetY(5,angle-90+180*c);
  CreateShot01(x,y,v,angle,color,delay);
          }
     }
   PlaySE(seshot1);
    wait(1);
      }
 ascent(a in 0..36){
  CreateShot01(GetX,GetY,v,GetAngleToPlayer+10*a+5,155,30);
   }
  PlaySE(seshot4); */
       }

   function Shot5{
    let way = 8;
   let delay = 10;
  let color = 155;
  let v = 1.5;
  let accel = 0.08;
  let base = GetAngleToPlayer;
   loop(10){
   ascent(a in 0..way){
    let angle = base + 360/way*a;
    let x = GetX;
    let y = GetY;
   CreateShot02(x,y,v,angle,accel,6,color, delay );
          }
   way += 4;
  base += rand(-10,10);
    PlaySE(seshot1);
    wait(15);
          }
       }

   function Shot6{
    let way = 7;
   let delay = 30;
  let color = WHITE02;
  let v = 6;
  let base = GetAngleToPlayer;
  let d = 90;
   loop(17){
   ascent(a in 0..way){
    let angle = base+d*(a-3);
    let x = GetX;
    let y = GetY;
   CreateShot01(x,y,v,angle,color, delay );
          }
 d -= 5.4;
    PlaySE(seshot3);
    wait(8);
          }
       }
    }

    function Move{
   ascent(a in 0..18){
      SetAlpha(255-15*a);
   if(a < 15){vanish = true;}
   wait(2);
      }
   SetX(rand(minx+64,maxx-64));
   SetY(miny+rand(32,140));
      ascent(a in 0..18){
      SetAlpha(15*a);
   if(a >= 15){vanish = false;}
   wait(2);
      }
    }

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

  task SpinMotion(f){
      ascent(a in 0..4){
         sgr(7,a);
       wait(f/4);
            }
          sgr(0,0);
      }

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

script_event Talk{
    @Initialize{
  }
    @MainLoop{
  if(GetPlayerType != USER_PLAYER){
    TextOutB(120,"\c[RED]ちょっと・・・");
    TextOutB(120,"\c[RED]勝手に人の家を荒らし回って");
     TextOutB(120,"\c[RED]何のつもりかしら？");
          }
       End;
      }
   @Finalize{
      }
    }