
#Title[「フラッドオブレイ」]
#Text[幻月・スペル2]
#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(600);
      SetDamageRate(10,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)); 
       }   
  if(GetMissCountInThisSpell != 0){CreateItem(ITEM_1UP,GetX,GetY); }
 else{
   loop(3){CreateItem(ITEM_BOMB,rand(minx,maxx),miny+rand(16,150));}
     loop(100){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,150)); 
         }   
       }
     }
 
     task TMain{
    yield;
     SetGraphicScale(0,0);
    SetX(rand(minx+64,maxx-64));
   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(10,0);}
    wait(1);
      }
    }

   task Shot{
  loop{
 Concentration01(60);
   wait(60);
   sgr(3,2);
   let base = 300; 
  ascent(b in 0..30){
 let v = 8;
  let way = b+1;
 if(b >= 4){way = 5;}
   ascent(d in 0..way){
  ascent(a in 0..2){
  let angle = 90+(base-b*10-(10+20/3)*d)*(-1)^a;
    ascent(c in 0..2){
  let x = GetX+5+offsetX(4,angle+90*(-1)^c);
  let y = GetY-25+offsetY(4,angle+90*(-1)^c);
  CreateShot01(x,y,v,angle,174,0);
      }
    }
   }
   PlaySE(seshot1);
   wait(2);
    }
  wait(30);
  Move;
  Concentration01(60);
   wait(60);
   sgr(3,2);
  ascent(a in 0..5){
    let angle = -90+30*(a-2);
  CreateLaserA(1,GetX+5,GetY-55,0,20,192,30);
  SetLaserDataA(1,0,angle,0,10,0,0);
  SetLaserDataA(1,30,angle,0,0,0,0);
   SetShotKillTime(1,120);
   FireShot(1);
      }
  PlaySE(dlaser);
  wait(30);
  L;
  sgr(0,0);
  CreateLaserA(0,GetX,GetY+35,500,(maxx-minx)/16*10,BLUE01,60);
  SetLaserDataA(0,0,90,0,0,0,0);
   SetShotKillTime(0,150);
   FireShot(0);
   wait(60);
  PlaySE(MS);
   ascent(b in 0..9){
   let angle = GetAngleToPlayer+15*(b-4);
  ascent(a in 0..12){
    CreateShot01(GetX,GetY,1+0.7*a,angle,8,0);
         }
      wait(6);
       }
   wait(30);
  Move;
     }
    }

 task L{
 ascent(a in 0..20){
  let x = (maxx-minx)/16*a+minx-20+rand(-(maxx-minx)/32,(maxx-minx)/32);
   CreateLaserA(0,x,miny-30,600,20,192,60);
  SetLaserDataA(0,0,90,0,0,0,0);
   SetShotKillTime(0,60);
   FireShot(0);
ascent(a in 0..20){
 CreateShot01(x,miny-30,10,90,152,60+4*a);
    }
  }
  loop(60){PlaySE(dlaser);wait(1);}
 }

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