
#Title[pXBʏe2]
#Text[pXBʏe2]
#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-kaze-ti2.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\tm2_gun002.wav";
   let se2 = csd~ "bgm\tm2_coin000.wav";
   let se3 = csd~ "bgm\concentration.wav";
   let se4 = csd~ "bgm\countdown.wav";
   let arrayL = [];
let dif = GetCommonData("Dif");
   @Initialize{
           if(GetPlayerType == REIMU_A){SetLife(2200);}
            else{SetLife(2200);}
           SetTimer(60);
           SetDamageRate(80,80);
   /*   if(dif == 2){SetDamageRate(80,4);}*/
           SetInvincibility(150);
           SetGraphicRect(64,1,128,64);
           SetMovePosition03(GetCenterX,GetClipMinY+100,20,5);	

           LoadGraphic(imgBOSS);
          /* SetTexture(imgBOSS); */
          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{
  SetShotAutoDeleteClip(64,64,64,64);
        DeleteGraphic(imgBOSS);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4);           
     }
 
     task TMain{
          yield;
       wait(120);
  SetShotAutoDeleteClip(150,150,150,150);
        if(dif == 1){Shot2;}
        else if(dif == 2){Shot1;}
     /*   Move;*/
        Count;
    }

      task Shot1{
       loop{
 let base = rand(-180,180);
     ascent(c in 0..6){
        ascent(b in 0..72){
        ascent(a in 0..5){
           let radius = 0;
          let angle = base + a + b*5;
          let v = 4-c*0.6;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 182;
          let delay = 0;
         let accel = 0;
         let angle2 = GetAngleToPlayer;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,0,v,color);
         SetShotDataA(0,50,4,angle+90*(-1)^b-90,0,accel,v,color);
         FireShot(0);
       }
       }
    base += rand(-2.5,2.5);
       }
  PlaySE(se1);
     wait(50);
       PlaySE(se2);
      wait(80);
      Move;
        }
    }

   task Shot2{
       loop{
     ascent(c in 0..3){
    let base = rand(-180,180);
        ascent(b in 0..36){
        ascent(a in 0..10){
           let radius = 0;
          let angle = base + a + b*10;
          let v = 3-c*1.2;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 182;
          let delay = 0;
         let accel = 0;
         let angle2 = GetAngleToPlayer;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,0,v,color);
         SetShotDataA(0,50,3,angle+90*(-1)^b-90,0,accel,v,color);
         FireShot(0);
       }
       }
       }
  PlaySE(se1);
     wait(50);
       PlaySE(se2);
      wait(80);
      Move;
        }
    }

     task Move{
        let x = rand(40,40);
        let y = rand(8,16);
        let v = 1;
        let xmin = GetClipMinX+96;
        let ymin = GetClipMinY+60;
        let xmax = GetClipMaxX-96;
        let ymax = GetClipMinY+120;
    /*    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,0,1*128,128); 
         wait(90); */
    }
       
      task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }
     
    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;}
       }
}