
#Title[幽香・スペル2]
#Text[春符 「ポルン地獄」]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
 #include_function".\function_effect.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;
  let mirage = false;
  let name        = "春符 「ポルン地獄」";

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

   @MainLoop{
    if(OnEvent){break;}
   if(!vanish && !OnBomb){
           SetCollisionA(GetX, GetY, 24);
           SetCollisionB(GetX, GetY, 18);
        }
   if(!vanish && mirage && !OnBomb){
       SetCollisionA(2*cx-GetX, GetY, 24);
        SetCollisionB(2*cx-GetX, GetY, 18);
        }
         yield;
       }

   @DrawLoop{
         SetTexture(imgBOSS);  
        DrawGraphic(GetX,GetY);
   if(mirage == true){DrawGraphic(2*cx-GetX,GetY);}
     }

    @Finalize{
  if(!IsTimeOut){
  loop(96){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,150)); 
       } 
     CreateItem(ITEM_1UP,GetX,GetY); 
         } 
  SetCommonDataEx("","bg",7);
   PlaySE(sevanish);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
     }
 
     task TMain{
  yield;
  SpinMotion(48);
 SetX(cx);
   SetY(miny+120);
      ascent(a in 0..18){
      SetAlpha(15*a);
   if(a >= 15){vanish = false;}
   wait(2);
      }
  Circle2(60);
  CutIn(KOUMA, name, "", 0, 0, 0, 0);
  SetScore(2000000);
  SetTimer(48);
   SetInvincibility(120);
          wait(90);
        Shot;
  SpinMotionEndless(48);
    loop{
   if(OnBomb){
   SetAlpha(0);
   SetDamageRate(0,0);}
     else {
  SetAlpha(255);
   SetDamageRate(100,0);}
    wait(1);
      }
    }

   task Shot{
   Shot1; Shot3;
   task Shot1{
  let color = 3; let delay = 0;
  loop{
   let x = GetX; let y = GetY;
   let base = GetAngleToPlayer;
      ascent(d in 0..10){
   let v = 3+0.2*d;
      ascent(b in 0..2){
    ascent(a in 0..16){
   let angle = base+45*a+15/8*d*(-1)^b-6*(-1)^b;
    CreateShot01(x,y,v,angle,color,delay);
          }
          }
       wait(3);
          }
  base = GetAngleToPlayer;
      ascent(d in 0..10){
    let v = 3+0.2*d;
      ascent(b in 0..2){
    ascent(a in 0..16){
   let angle = base+45*a-15/8*d*(-1)^b+34*(-1)^b;
    CreateShot01(x,y,v,angle,color,delay);
          }
          }
       wait(3);
          }
         }
       }
  task Shot3{
  while(GetLife > 1500 && GetTimer > 30){wait(1);}
    let way = 8;
   let delay = 10;
  let color = 2;
  let base = GetAngleToPlayer;
   loop{
   loop(way){
    let angle = rand(-180,180);
   let v = rand(0.1,3);
    let accel = rand(0.005,0.03);
    let x = GetX;
      let y = GetY;
     GravityShot( x, y,v, angle,accel,90, color, delay );
          }
    PlaySE(seshot4);
    wait(10);
  if(GetLife > 1000 && GetTimer > 20){ wait(5);}
  if(GetLife > 500 && GetTimer > 10){ wait(5);}
          }
       }
    }

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

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

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