
#Title[「夢幻世界」]
#Text[幻月・スペル5]
#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(10000000);  */
           SetLife(3000);
      SetDamageRate(100,0);
       /*    SetTimer(180); 
           SetInvincibility(120);  */
         sgr(0,0);
      /*   SetMovePosition03(GetCenterX,GetClipMinY+100,20,5);*/
        SetAlpha(255);
           LoadGraphic(imgBOSS);
    LoadGraphic(effect);
          LoadUserShotData(shotData);
   Circle2(60);
 SetEffectForZeroLife(40,128,2);
           TMain;
    }

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

         yield;
       }

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

    @Finalize{
  PlaySE(sevanish);
 SetCommonDataEx("","bg",8);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
 if(!IsTimeOut){
  loop(2010){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,224)); 
       }   
     }
  }
 
     task TMain{
    yield;
     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(60);  
    CutIn(KOUMA, name, "", 0, 0, 0, 0);  
     SetScore(10000000);
  SetDamageRate(20,0);
       SetTimer(180); 
         SetInvincibility(120);
    Concentration01(90);
    wait(90);
        Shot;
        Count;
    loop{
   if(OnBomb){
   SetAlpha(0);
   SetDamageRate(0,0);}
     else{
    SetAlpha(255);
   SetDamageRate(20,0);}
    wait(1);
      }
    }

   task Shot{
  sgr(3,2);
 let color = [8,40];
  let delay = 10;
  let v = 8; let w = 2;
  loop{
  if(GetLife >= 2500 && GetTimer >= 60){v = 3; w = 60;}
  else if(GetLife >= 2000 && GetTimer >= 60){v = 4; w = 45;}
  else if(GetLife >= 1500 && GetTimer >= 60){v = 5; w = 30;}
  else if(GetLife >= 1000 && GetTimer >= 60){v = 6; w = 15;}
  else if(GetLife >= 500 && GetTimer >= 60){v = 7; w = 10;}
  else if(GetLife < 500 || GetTimer < 60){v = 8; w = 5;}
  if(GetLife <= 0 || GetTimer <= 0){v = 10; w = 1;}
  let i = rand_int(0,1);
  let x = GetX+rand(-32,32);
  let y = GetY+rand(-32,32);
  let base = rand(-180,180);
  ascent(a in 0..36){
  CreateShot01(x,y,v,base+10*a,color[i],delay);
      }
  PlaySE(seshot1);
   wait(w);
       }
    }

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