
#Title[「破滅の予兆」]
#Text[幻月・スペル3]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
   let name        = " 「破滅の予兆」";
   let imgBOSS = csd~"img\dot_gengetu.png";
   let shotData = csd ~ "data_usershot.txt";
  let effect = csd ~ "img\circle.png"; 
  let vanish = true;

   @Initialize{
 SetCommonDataEx("","bg",10);
     CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(5000000);
           SetLife(4000);
      SetDamageRate(50,0);
           SetTimer(99);
           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 && !vanish){
      SetCollisionA(GetX, GetY, 24);
      SetCollisionB(GetX, GetY, 18);
     }

         yield;
       }

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

    @Finalize{
 SetCommonDataEx("","bg",8);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
  loop(100){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,150)); 
       }   
  CreateItem(ITEM_1UP,GetX,GetY); 
     }
 
     task TMain{
    yield;
 vanish = false;
   SetX(cx);
   SetY(miny+100);
   /*  SetGraphicScale(0,0);
    SetX(cx);
   SetY(miny+100);
     ascent(a in 0..21){
     SetGraphicScale(a*0.05,a*0.05);
   if(a >= 15){vanish = false;}
      wait(1);
        }
          wait(90);  */
        Shot;
        Count;
    loop{
   if(OnBomb){
   SetAlpha(0);
   SetDamageRate(0,0);}
     else{
    SetAlpha(255);
   SetDamageRate(50,0);}
    wait(1);
      }
    }

   task Shot{
  sgr(3,2);
   ShotA;  ShotB;
  task ShotA{
  let t = 0;
  let v = 4;
  let color = 8;
  let delay = 0;
 let base = rand(-180,180);
  let s = 9;
  let f = 0;
  if(GetPlayerX <= cx){s = -9; f = -10;}
    else if(GetPlayerX >= cx){s = 9; f = 10;}
  loop{
    ascent(c in 0..2){
   ascent(a in 0..8){
   let angle = base+rand(-0.5,0.5)+10*a+180*c+t;
    CreateShot01(GetX,GetY,v,angle,color,delay);
           }
         }
  t += s; 
  PlaySE(seshot1);
 if(GetPlayerX <= cx){f -= 1;}
    else if(GetPlayerX >= cx){f += 1;}
  if(f <= -10){s = -9; f = -10;}
  else if(f >= 10){s = 9; f = 10;}
     wait(4);
       }
      }
   task ShotB{
  let v = 6; let accel = -0.1; let vmin = 2;
  let color = WHITE02; let delay = 40;
  let base = 0;
  let base2 = base+180;
   loop{
   ascent(a in 0..11){
  let dy = rand(-15,15);
    ascent(c in 0..3){
   let angle = GetAngleToPlayer+base + 2*(c-1);
   let angle2 = GetAngleToPlayer+base2 + 2*(c-1);
  let x = GetX+offsetX((cx-minx)/10*(a+1),0);
  let x2 = GetX+offsetX((cx-minx)/10*(a+1),180);
  CreateShot02(x,GetY+dy,v,angle,accel,vmin,color,delay);
   CreateShot02(x2,GetY+dy,v,angle2,accel,vmin,color,delay);
         }
     base += 15;
  base2 -= 15;
    wait(5);
     }
      }
      }
    }

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