
#Title[AXXy1]
#Text[AXXy1]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    let name        = "G{@uUEOA@`́`v";
     let csd = GetCurrentScriptDirectory;
        let gx = GetX;
        let gy = GetY;
        let gspeed = GetSpeed;
        let gangle = GetAngle;     
        let arg = GetArgument;
   let imgBOSS = csd~"img\character\dot_alice.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\arrow01.wav";
   let se2 = csd~ "bgm\bell01.wav";
   let se3 = csd~ "bgm\warp03.wav";
   let se4 = csd~ "bgm\countdown.wav";
    let effect = csd ~ "img\magic_circle\powercircle.png";
   let arrayL = [];
 let dif = GetCommonData("Dif");
  if(dif == 2){name   = "G{@uUEOA@`Í`v";}
   @Initialize{
       CutIn(KOUMA, name, "", 0, 0, 0, 0);
           if(GetPlayerType == REIMU_A){SetLife(800);}
            else{SetLife(800);}
           SetTimer(75);
     SetScore(6000000);
       SetDamageRate(20,10);
  if(dif == 2){SetDurableSpellCard;}
           SetInvincibility(120);
           SetGraphicRect(0*128,0,1*128,128);   
           SetMovePosition03(GetCenterX,GetClipMinY+120,20,5);
        SetAlpha(255);
      MagicCircle(false);
           LoadGraphic(imgBOSS);
          LoadGraphic(effect);
          LoadUserShotData(shotData);
         LoadSE(se1);LoadSE(se2);LoadSE(se3);LoadSE(se4);
           TMain;
    }

   @MainLoop{
           SetCollisionA(GetX, GetY, 24);
           SetCollisionB(GetX, GetY, 24);

         yield;
       }

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

    @Finalize{
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4);  
       if(!IsTimeOut){
                loop(125){
              CreateItem(ITEM_SCORE,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
              }
           }         
     }
 
     task TMain{
          yield;
      Circle(40);
       wait(120);
    SetGraphicRect(0*128,2*128,1*128,3*128); 
       if(dif == 1){ Shot; }
     else if(dif == 2){Shot2; Move2;}
        Count;
    }

      task Shot{ 
    let s = 0;
      let way = 37;
   loop{
       let x = GetX; let y = GetY;
       let color = 241; let delay = 0;
    loop(8){
       ascent(a in 0..way){
        let v = rand(0.5,6);
        let angle = GetAngleToPlayer+180/way*(a-(way-1)/2);
        CreateShot01(x,y,v,angle,color,delay);
      }
      PlaySE(se1);
       wait(5);
      }
       wait(150); 
     Bullet(s);
    task Bullet(s){
      let base = GetAngleToPlayer;
      ascent(c in 0..12){
       ascent(b in 0..8){
       let x = GetX; let y = GetY;
       let color = 40; let delay = 0;
        let v = 5;
       let angle = base+45*b+6*c*(-1)^s;
       CreateShot01(x,y,v,angle,color,delay);
       }
        PlaySE(se1);
       wait(10);
       }
       }
     Bullet2;
    task Bullet2{
      let base = GetAngleToPlayer;
    loop(2){
       ascent(c in 0..6){
       ascent(b in 0..8){
        let x = GetX;
        let y = GetY;
        let v = 8;
        let w = 15;
        let angle = base+45*b+8*c;;
        let angle2 = atan2(GetPlayerY-GetY-offsetY(w*v,angle),GetPlayerX-GetX-offsetX(w*v,angle));
         let color = 241;
          let delay = 10;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,0,v,color);
         SetShotDataA(0,w,0,angle2,0,0,0,color);
         SetShotDataA(0,w+30,v,angle2,0,0,v+2,color);
         FireShot(0);
            }
        wait(10);
          }
        Move;
          }
        }
      s += 1;
       wait(150);
  Laser;
  task Laser{
  let length = 500; let width = 15;
  let color = 191; let delay = 90;
  let radius = 32; let span = 180;
  loop(6){
   ascent(a in 0..2){
   let angle = GetAngleToPlayer+span*(-1)^a;
   CreateLaserB(1,length,width,color,delay);
     SetLaserDataB(1,0,0,radius,0,angle,-span*(-1)^a/30,angle,-span*(-1)^a/30);
        SetLaserDataB(1,30,0,NULL,0,NULL,0,NULL,0);
         SetShotKillTime(1,150);  
        FireShot(1);
         }
    wait(10);
      }
      }
  wait(90);
    }
  }

  task Shot2{
    ShotA;
    task ShotA{
   let base = 0;
   let v = 5; let vmin = 3;
   let accel = -10;
    let delay = 10;
   let color = 115;
    let radius = 16;
  let w = 5;
   loop{
   if(GetLife <= 720 || GetTimer <= 65){
       v = 5.0; vmin = 3.5; 
      }
    if(GetLife <= 640 || GetTimer <= 55){
       v = 5.0; vmin = 4.0;  w = 4;
      }
     if(GetLife <= 560 || GetTimer <= 50){
      v = 5.0; vmin = 4.5; 
      }
    if(GetLife <= 480 || GetTimer <= 40){
      v = 5.0; vmin = 5.0;  w = 3;
      }
    if(GetLife <= 400 || GetTimer <= 35){
      v = 5.0; vmin = 5.5;  
      }
    if(GetLife <= 320 || GetTimer <= 25){
       v = 5.0; vmin = 6;  w = 3;
      }
    if(GetLife <= 240 || GetTimer <= 20){
      v = 5.0; vmin = 6.5; 
      }
   if(GetLife <= 160 || GetTimer <= 10){
       v = 5.0; vmin = 7; w = 3;
      }
    if(GetLife <= 80 || GetTimer <= 5){
       v = 5.5; vmin = 7.5; 
      }   
    ascent(a in 0..9){
    let angle = base + 10*(a-4);
     let x = GetX+offsetX(radius,angle);
     let y = GetY+offsetY(radius,angle);
    CreateShot02(x,y,v,angle,accel,vmin,color,delay);
     }
 let x1 = GetX;
  /*  base += rand(30,30);*/
    PlaySE(se2);
    wait(w); 
  let x2 = GetX;
  if(x2-x1 >= 0){base += 20;}
  else if(x2-x1 < 0){base += 20;}
       }
      }
 ShotB; 
    task ShotB{
   let base = 180;
   let v = 5; let vmin = 3;
   let accel = -0.1;
    let delay = 10;
   let color = 115;
    let radius = 16;
  let w = 5; let n = 20;
   loop{
  if(GetLife <= 720 || GetTimer <= 65){
       v = 5.0; vmin = 3.5; n = 30;
      }
    if(GetLife <= 640 || GetTimer <= 55){
       v = 5.0; vmin = 4;  n = 50; w = 4;
      }
     if(GetLife <= 560 || GetTimer <= 50){
       v = 5.0; vmin = 4.5; n = 70;
      }
    if(GetLife <= 480 || GetTimer <= 40){
       v = 5.0; vmin = 5; n = 80;w = 3;
      }
    if(GetLife <= 400 || GetTimer <= 35){
       v = 5.0; vmin = 5.5; n = 99;
      }
    if(GetLife <= 320 || GetTimer <= 25){
       v = 5.0; vmin = 6;  n = 99;w = 3;
      }
    if(GetLife <= 240 || GetTimer <= 20){
       v = 5.0; vmin = 6.5;  n = 99;
      }
   if(GetLife <= 160 || GetTimer <= 10){
       v = 5.0; vmin = 7;  n = 99;w = 3;
      }
    if(GetLife <= 80 || GetTimer <= 5){
       v = 5.3; vmin = 7.5;  n = 99;
      }   
    ascent(a in 0..9){
    let id = rand_int(0,99);
    let angle = base + 10*(a-4);
     let x = GetX+offsetX(radius,angle);
     let y = GetY+offsetY(radius,angle);
  if(id <= n){
    CreateShot02(x,y,v,angle,accel,vmin,color,delay);
       }
     }
  let x1 = GetX;
  /*  base += rand(30,30); */
    PlaySE(se2);
    wait(w);
  let x2 = GetX;
  if(x2-x1 >= 0){base += 20;}
  else if(x2-x1 < 0){base += 20;}
       }
      }
    }

     task Move{
        let x = rand(32,64);
        let y = rand(0,32);
        let v = 1;
        let xmin = GetClipMinX+64;
        let ymin = GetClipMinY+60;
        let xmax = GetClipMaxX-64;
        let ymax = GetCenterY-60;
        if(x>=GetX){SetGraphicRect(1*128,1*128,2*128,2*128);}
       else if(x<=GetX){SetGraphicRect(1*128,1*128,2*128,2*128);}
         SetMovePositionRandom01(x,y,v,xmin,ymin,xmax,ymax);
         wait(90);
         SetGraphicRect(0*128,2*128,1*128,3*128); 
         wait(90);
    }
       
      task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }
     
 task Move2{
        let xmin = GetCenterX-10;
        let ymin = GetClipMinY+60;
        let xmax = GetCenterX+10;
        let ymax = GetClipMinY+120;
    let v = 30;
    loop{
 if(GetLife <= 640 || GetTimer <= 55){ xmin = GetCenterX-20; xmax = GetCenterX+20;}
   if(GetLife <= 480 || GetTimer <= 40){ xmin = GetCenterX-40; xmax = GetCenterX+40;}
   if(GetLife <= 320 || GetTimer <= 25){ xmin = GetCenterX-60; xmax = GetCenterX+60;}
   if(GetLife <= 160 || GetTimer <= 10){ xmin = GetCenterX-80; xmax = GetCenterX+80;}
      SetMovePosition02(xmin,rand(ymin,ymax),v);
       wait(v);
       SetMovePosition02(xmax,rand(ymin,ymax),v);
       wait(v);
      }
    }

   task Circle(size){
           let c= Obj_Create(OBJ_EFFECT);
             Obj_SetX(c,GetX);
             Obj_SetY(c,GetY);
             Obj_SetAngle(c,0);
             ObjEffect_SetAngle(c,0,0,0);
             ObjEffect_SetTexture(c,effect);
             ObjEffect_SetRenderState(c,ADD);
             ObjEffect_SetPrimitiveType(c,PRIMITIVE_TRIANGLEFAN);
             ObjEffect_SetLayer(c,0);
             ObjEffect_CreateVertex(c,62);
             ObjEffect_SetVertexXY(c,0,0,0);
             ObjEffect_SetVertexUV(c,0,128,128);
             ObjEffect_SetVertexColor(c,0,255,255,255,255);
             ObjEffect_SetScale(c,size/10,size/10);

            ascent(let i in 0..61){
                ObjEffect_SetVertexXY(c,i+1,cos(i*6)*20,sin(i*6)*20);
                ObjEffect_SetVertexUV(c,i+1,cos(i*6)*130+130,sin(i*6)*130+130);
                ObjEffect_SetVertexColor(c,i+1,255,255,255,255);
            }
       Spin;
       Up;
     task Spin{
      let h = 0;
         loop{
            Obj_SetX(c,GetX); Obj_SetY(c,GetY);
            ObjEffect_SetAngle(c,0,0,h);
            h += 8;
            wait(1);
           }
         }
       task Up{
            loop{
             ascent(a in 0..30){
            Obj_SetX(c,GetX); Obj_SetY(c,GetY);
            ObjEffect_SetScale(c,(size+a/5)/10,(size+a/5)/10);
            wait(1);
             }
            wait(10);
             descent(a in 0..30){
            Obj_SetX(c,GetX); Obj_SetY(c,GetY);
            ObjEffect_SetScale(c,(size+a/5)/10,(size+a/5)/10);
            wait(1);
             }
            wait(10);
           }
        }
    }

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

       sub setGraphicStop  { SetGraphicRect( 1, 1, 64, 64); }

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