
#Title[pXBʏe1]
#Text[pXBʏe1]
#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,100);
     /*   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{
    if(OnEvent){break;}
           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;
 SetShotAutoDeleteClip(150,150,150,150);
     wait(120);
        if(dif == 1){Shot;}
   else if(dif == 2){Shot2;}
     /*   Move;*/
        Count;
    }

      task Shot{
       loop{
        ascent(c in 0..3){
        ascent(b in 0..3){
        ascent(a in 0..60){
           let radius = 0;
          let angle = 6*a+2*b;
          let v = 3; let v2 = 1.5;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 68;
          let delay = 0;
         let accel = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,0,v,color);
         SetShotDataA(0,80-c*10,0,angle,0,accel,v,color);
         SetShotDataA(0,120-c*10,v2,angle-10+10*b,0,accel,v,color);
         FireShot(0);
     }
      }
   PlaySE(se1);
      wait(10);
       }
     wait(90);
       PlaySE(se2);
      wait(60);
     Move;
         let color = 3+8*8;     
          let angle = GetAngleToPlayer;
          let v = 3;
          let radius = 0;
      loop(36){
       ascent(a in 0..1){
       let delay = 10*a;
      let x = GetX+offsetX(radius,angle);
      let y = GetY+offsetY(radius,angle);
      CreateShot01(x,y,v,angle,color,delay);
           }
       angle += 10;
          }
        }
    }

  task Shot2{
       loop{
        ascent(c in 0..6){
        ascent(b in 0..3){
        ascent(a in 0..60){
           let radius = 0;
          let angle = 6*a+2*b;
          let v = 3; let v2 = 1.5;
  if(c == 0 || c == 2 || c == 4){v2 = 1.5;}
  else if(c == 1 || c == 3 || c == 5){v2 = 4;}
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 68;
          let delay = 0;
         let accel = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,0,v,color);
         SetShotDataA(0,80-c*5,0,angle,0,accel,v,color);
         SetShotDataA(0,120-c*5,v2,angle-10+10*b+90*(-1)^c-90,0,accel,v,color);
         FireShot(0);
     }
      }

 let color = 3+8*8;     
       let base = rand(-180,180);
          let v = 3;
          let radius = 0;
      loop(36){
       ascent(a in 0..1){
       let delay = 10*a;
      let x = GetX+offsetX(radius,base);
      let y = GetY+offsetY(radius,base);
      CreateShot01(x,y,v,base,color,delay);
           }
       base += 10;
          } 

   PlaySE(se1);
      wait(5);
       }
     wait(90);
       PlaySE(se2);
      wait(90);
     Move;
   /*      let color = 3+8*8;     
          let angle = GetAngleToPlayer;
          let v = 3;
          let radius = 0;
      loop(72){
       ascent(a in 0..1){
       let delay = 5*a;
      let x = GetX+offsetX(radius,angle);
      let y = GetY+offsetY(radius,angle);
      CreateShot01(x,y,v,angle,color,delay);
           }
       angle += 5;
          }       */
        }
    }

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