#東方弾幕風
#Title[卯月「花映之月（エイプリールフルムーン）」]
#Text[LastWord　〜鈴仙・U・イナバ〜]
#Player[FREE]
#Image[.\img.png]
#BackGround[User]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
     #include_function".\function_bullet.txt"
    #include_function".\function_effect.txt"
   let name        = " 卯月「花映之月（エイプリールフルムーン）」";
   let imgBOSS = csd~"img\dot_reisen.png";
   let shotData = csd ~ "data_usershot.txt";
let difficult = GetCommonDataDefaultEx("","dif",8);
 let dx = [];
 let dy = [];

   @Initialize{
  SetCommonDataEx("","dif",difficult);
     CutIn(YOUMU, name, "", 0, 0, 0, 0);
  LastSpell;
 SetDurableSpellCard;
   SetScore(100000000/3);
   SetDamageRate(0,0);
           SetLife(1);
           SetTimer(99);
           SetInvincibility(120);
         sgr(0,0);
     SetX(cx); SetY(miny+120);
           LoadGraphic(imgBOSS);
          LoadUserShotData(shotData);
  SetTexture(imgBOSS); 
  SetEffectForZeroLife(0,0,0);
           TMain;
    }

   @MainLoop{
    if(OnEvent){break;}
  /*   if(!phantom){
      SetCollisionA(GetX, GetY, 24);
      SetCollisionB(GetX, GetY, 20); 
         }  */

         yield;
       }

   @DrawLoop{
  DG;
  SetRenderState(ADD);
  SetGraphicScale(1,1);
   SetAlpha(255);
  SetColor(255,255,255); 
  if(phantom){ SetColor(255,0,0); }
        DrawGraphic(GetX,GetY);
     }

    @Finalize{
 PlaySE(sevanish);
        DeleteGraphic(imgBOSS);
     }
 
      task TMain{
 SpellBackGround(100);
       SetEnemyMarker(true);
        Count;
   wait(120);
       Shot;
    Winder;
    }

   task Shot{
   let m = 14;
   let k = 0;
    let d = 0;
   let v = 1.62;
   let color = 89;
   let color2 = 97;
    let delay = 10;
    let way = 8;
   let radius = 24;
  while(GetTimer >= 10){
  let base = -90;
     ascent(c in 0..24){
   ascent(a in 0..way){
   let angle = 360/way*a-base;
   let x = GetPlayerX+offsetX(radius,angle);
   let y = GetPlayerY+offsetY(radius,angle);
   P(x,y,v,angle,color,color2,delay,1.5,0,45,1,219+30*m);
    angle = 360/way*a+base;
     let x = GetPlayerX+offsetX(radius,angle);
     let y = GetPlayerY+offsetY(radius,angle);
   P(x,y,v,angle,color,color2,delay,-1.5,0,135,1,219+30*m);
        }
  if(c == 6 || c == 13 || c == 21){Move;}
   PlaySE(seshot1);
   base += k;
   k+=d;
    wait(9);
        }
   wait(3);
  /*if(m >= 18){Slow(2);}*/
   RE(90);
   wait(90);
    loop(m){
       wait(30);
      Move;
    }
    Slow(0);
  sgrnum = 0;
   d += 1;
   way += 2;
   m++;
   v += 0.02;
        }
      }

  task Winder{
  wait(219);
  let radius = 24;
   let color = 94;
  let color2 = 38;
  let delay = 5;
  let m = 420;
       while(GetTimer >= 5){
    while(!phantom){
     ascent(a in 0..10){
    let angle = GetAngleToPlayer+36*a+18;
  let x = GetX+offsetX(radius,angle);
  let y = GetY+offsetY(radius,angle);
      ascent(b in 0..2){
     let v = 0.5+b*5;
    P2(x,y,v,angle,color,color2,delay,0,0,0,0,0);
             }
          }
    wait(10);
        }
    while(phantom){wait(1);}
   wait(m);
  m += 30;
          }
        }

 task Move{
   let f = 3;
  let r = rand_int(0,1);
 if(GetX < minx+100){r = 0;}
 else if(GetX > maxx-100){r = 1;}
 else if(GetX < GetPlayerX){r = 0;}
 else if(GetX > GetPlayerX){r = 1;}
    let x = GetX + rand(30,100)*(-1)^r;
    let y = GetY + rand(-32,32);
    if(y < miny+60){y = miny+60;}
    else if(y > miny+150){y = miny+150;}
   if(GetX > x){sgrnum = 1;}
   else if(GetX < x){sgrnum = 2;}  
    SetMovePosition03(x,y,15,f);
    }

  task RE(w){
  SetColor(255,0,0);
   phantom = true;
   SpellBackPhantom(100);
  RedEye(60,cx+80,cy-30,150);
  RedEye(60,cx-80,cy-30,30);
 MotionBlurEx(ALL,w,128,ALPHA);
  PlaySE(redeye);
  sgrnum = 4;
  wait(w);
   sgrnum = 0;
   phantom = false;
  SetColor(255,255,255);
    }


 task DG{
  dx = dx~[GetX+offsetX(rand(0,24),rand(-180,180))];
  dy = dy~[GetY+offsetY(rand(0,24),rand(-180,180))];
 ascent(a in 0..length(dx)){
  SetRenderState(ALPHA);
  SetAlpha(10*(a+1));
  SetGraphicScale(1.3-0.015*a,1.3-0.015*a);
  SetColor(255,10*(a+1),10*(a+1));
  DrawGraphic(dx[a],dy[a]);
   }
  if(length(dx) > 30){dx = erase(dx,0); dy = erase(dy,0);}
   }

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