
#Title[럤믅륂뭙뼀2]
#Text[럤믅륂뭙뼀2]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
     let csd = GetCurrentScriptDirectory;
        let gx = GetX;
        let gy = GetY;
        let gspeed = GetSpeed;
        let gangle = GetAngle;     
        let arg = GetArgument;
   let imgBOSS = csd~"img\character\dot_yukari.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\arrow01.wav";
   let se2 = csd~ "bgm\eco02_a.wav";
   let se3 = csd~ "bgm\tm2_coin000.wav";
   let se4 = csd~ "bgm\countdown.wav";
    let effect = csd ~ "img\magic_circle\powercircle.png";
   let arrayL = [];
 let dif = GetCommonData("Dif");
   @Initialize{
           if(GetPlayerType == REIMU_A){SetLife(4000);}
            else{SetLife(4000);}
           SetTimer(60);
       SetDamageRate(100,20);
           SetInvincibility(120);
           SetGraphicRect(0*128,0,1*128,128);   
           SetMovePosition03(GetCenterX,GetClipMinY+160,20,20);
        SetAlpha(255);
           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);           
     }
 
     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;}
        Count;
    }

      task Shot{
     Bullet;
   task Bullet{
       let radius = 24;
       let delay = 0;
       let v = 8;
       let accel = 0;
       let vmax = v;
         loop{
         let base = GetAngleToPlayer;
         ascent(b in 0..360){
    ascent(a in 0..2){
      let color = rand_int(137,144);
       let angle = base+7*b+180*a;
       let angle2 = base-7*b+180*a;
       let x = GetX+offsetX(radius,angle);
       let y = GetY+offsetY(radius,angle);
       let x2 = GetX+offsetX(radius,angle2);
       let y2 = GetY+offsetY(radius,angle2);
    let xx =  GetX+offsetX(radius+v*16,angle);
    let yy =  GetY+offsetY(radius+v*16,angle);
    let xx2 = GetX+offsetX(radius+v*16,angle2);
    let yy2 = GetY+offsetY(radius+v*16,angle2);
    let after1 = atan2(GetPlayerY-yy,GetPlayerX-xx)+30;
    let after2 = atan2(GetPlayerY-yy,GetPlayerX-xx)-30;
    let after3 = atan2(GetPlayerY-yy2,GetPlayerX-xx2)+30;
    let after4 = atan2(GetPlayerY-yy2,GetPlayerX-xx2)-30;
    let after = [after1,after2,after3,after4];
    let i = rand_int(0,1); let h = rand_int(2,3);
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,accel,vmax,color);
         SetShotDataA(0,16,0,angle,0,accel,0,color);
         SetShotDataA(0,60,v,after[i],0,accel,vmax,color);
         FireShot(0); 
         CreateShotA(1,x2,y2,delay); 
         SetShotDataA(1,0,v,angle2,0,accel,vmax,color);
        SetShotDataA(1,16,0,angle,0,accel,0,color);
        SetShotDataA(1,60,v,after[h],0,accel,vmax,color);
         FireShot(1);
         wait(1); 
      }
       }
        Move;
          wait(120);
       } 
       }
       Bullet2;
      task Bullet2{
     wait(30);
     let color = 225; let delay = 0;
    let accel = 0; let vmax = 10;
      let radius = 0; 
     loop{
       loop(5){
      let base = GetAngleToPlayer-90;
     ascent(a in 0..2){
     let base2 = base +180*a;
      loop(36){
     let r = rand(-3,3);
      let v = rand(1,10);
       let angle = base2 + rand(-15,15);
       let x = GetX+offsetX(radius,angle);
       let y = GetY+offsetY(radius,angle);
       let xx =  GetX+offsetX(radius+v*20,angle)+r;
       let yy =  GetY+offsetY(radius+v*20,angle)+r;
       let after = atan2(GetPlayerY-yy,GetPlayerX-xx)+rand(-3,3);
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,accel,vmax,color);
         SetShotDataA(0,20,0,angle,0,accel,0,color);
         SetShotDataA(0,60,5,after,0,accel,vmax,color);
         FireShot(0);
       }
       PlaySE(se3);
       wait(30);
       }
       wait(90);
       }
     wait(120);
       }
       }
    }

  task Shot2{
     Bullet;
   task Bullet{
       let radius = 24;
       let delay = 0;
       let v = 8;
       let accel = 0;
       let vmax = v;
         loop{
         let base = GetAngleToPlayer;
         ascent(b in 0..360){
    ascent(a in 0..2){
      let color = rand_int(137,144);
       let angle = base+7*b+180*a;
       let angle2 = base-7*b+180*a;
       let x = GetX+offsetX(radius,angle);
       let y = GetY+offsetY(radius,angle);
       let x2 = GetX+offsetX(radius,angle2);
       let y2 = GetY+offsetY(radius,angle2);
    let xx =  GetX+offsetX(radius+v*16,angle);
    let yy =  GetY+offsetY(radius+v*16,angle);
    let xx2 = GetX+offsetX(radius+v*16,angle2);
    let yy2 = GetY+offsetY(radius+v*16,angle2);
    let after1 = atan2(GetPlayerY-yy,GetPlayerX-xx)+30;
    let after2 = atan2(GetPlayerY-yy,GetPlayerX-xx)-30;
    let after3 = atan2(GetPlayerY-yy2,GetPlayerX-xx2)+30;
    let after4 = atan2(GetPlayerY-yy2,GetPlayerX-xx2)-30;
    let after = [after1,after2,after3,after4];
    let i = rand_int(0,1); let h = rand_int(2,3);
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,accel,vmax,color);
         SetShotDataA(0,16,0,angle,0,accel,0,color);
         SetShotDataA(0,60,v,after[i],0,accel,vmax,color);
         FireShot(0); 
         CreateShotA(1,x2,y2,delay); 
         SetShotDataA(1,0,v,angle2,0,accel,vmax,color);
        SetShotDataA(1,16,0,angle,0,accel,0,color);
        SetShotDataA(1,60,v,after[h],0,accel,vmax,color);
         FireShot(1);
         wait(1); 
      }
       }
        Move;
          wait(120);
       } 
       }
       Bullet2;
      task Bullet2{
     wait(30);
     let color = 225; let delay = 0;
    let accel = 0.1; 
      let radius = 0;   let vmax = 10;
     loop{
       loop(5){
      let base = GetAngleToPlayer-45;
     ascent(a in 0..4){
     let base2 = base +90*a;
      loop(36){
     let r = rand(-3,3);
      let v = rand(1,10);
       let angle = base2 + rand(-15,15);
       let x = GetX+offsetX(radius,angle);
       let y = GetY+offsetY(radius,angle);
       let xx =  GetX+offsetX(radius+v*20,angle)+r;
       let yy =  GetY+offsetY(radius+v*20,angle)+r;
       let after = atan2(GetPlayerY-yy,GetPlayerX-xx)+rand(-3,3);

         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,0,v,color);
         SetShotDataA(0,20,0,angle,0,0,0,color);
         SetShotDataA(0,60,0,after,0,accel,rand(0.5,10),color);
         FireShot(0);
       }
       PlaySE(se3);
       wait(0);
       }
       wait(60);
       }
     wait(120);
  loop(30){
      let base = GetAngleToPlayer-45;
     ascent(a in 0..4){
     let base2 = base +90*a;
      loop(36){
     let r = rand(-3,3);
      let v = rand(1,10);
       let angle = base2 + rand(-15,15);
       let x = GetX+offsetX(radius,angle);
       let y = GetY+offsetY(radius,angle);
       let xx =  GetX+offsetX(radius+v*20,angle)+r;
       let yy =  GetY+offsetY(radius+v*20,angle)+r;
       let after = atan2(GetPlayerY-yy,GetPlayerX-xx)+rand(-0,0);
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,0,vmax,color);
         SetShotDataA(0,20,0,angle,0,0,0,color);
         SetShotDataA(0,60,0,after,0,accel,vmax,color);
         FireShot(0);
       }
       PlaySE(se3);
       wait(0);
       }
       wait(10);
       }
     wait(120);
       }
       }
    }

     task Move{
        let x = rand(64,92);
        let y = rand(0,32);
        let v = 2;
        let xmin = GetClipMinX+64;
        let ymin = GetClipMinY+60;
        let xmax = GetClipMaxX-64;
        let ymax = GetCenterY-60;
        if(x>=GetX){SetGraphicRect(2*128,3*128,3*128,4*128);}
       else if(x<=GetX){SetGraphicRect(2*128,1*128,3*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 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;}
       }
}