
#Title[僷儖僗傿僗儁儖2]
#Text[僷儖僗傿僗儁儖2]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
     let name        = "庺鎓丂乽庺偄偺揃乿乿";
     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\warp01.wav";
   let se2 = csd~ "bgm\tm2_coin000.wav";
   let se3 = csd~ "bgm\bell01.wav";
   let se4 = csd~ "bgm\countdown.wav";
   let arrayL = [];
 let dif = GetCommonData("Dif");
 if(dif == 2){name = "椢晞丂乽椢怓偺尪憐嫿乿";}
   @Initialize{
         CutIn(KOUMA, name, "", 0, 0, 0, 0);
           if(GetPlayerType == REIMU_A){SetLife(1250);}
            else{SetLife(1250);}
           SetTimer(60);
           SetDamageRate(40,45);
    /*  if(dif == 0){SetDamageRate(40,0);}*/
           SetScore(1500000);
           SetInvincibility(180);
           SetGraphicRect(64,1,128,64);
           SetMovePosition03(GetCenterX,GetClipMinY+130,10,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{
        DeleteGraphic(imgBOSS);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4); 
        if(!IsTimeOut){
                loop(54){
              CreateItem(ITEM_SCORE,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
              }
           }          
     }
 
     task TMain{
          yield;
       wait(180);
        if(dif == 1){Shot;}
     else if(dif == 2){Shot2;}
     /*   Move; */ 
        Count;
    }

      task Shot{
 function nextshot{
      while(GetEnemyShotCountEx(GetX,GetY,600,180) != 0){
    wait(1);
     }
   }
     let way = 8;
    let v = 2.5;
       loop{
   ascent(b in 0..2){
   let spin = 1-2*b;
    let base = rand(-180,180);
    let shotangle = rand(-180,180);
          ascent(a in 0..way){
          let radius = 16;
          let angle = base+360/way*a;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
          let color = 180;
          let delay = 0;
         Seed(x,y,v,angle,color,delay,spin,shotangle);
         }
    PlaySE(se3);
   wait(90);
        Move; 
  nextshot;
     way += 1;
   if(way > 36){way = 36;}
         }
        }
    }

  task Shot2{
   loop{
   typeB;
  nextshot;
   typeA(1);
   nextshot;
   typeA(-1);
    nextshot;
    typeA(1);
   nextshot;
    typeB;
  nextshot;
   typeA(-1);
  nextshot;
    typeA(1);
  nextshot;
    typeA(-1);
   nextshot;
      }
   function nextshot{
      while(GetEnemyShotCountEx(GetX,GetY,600,52) != 0){
    wait(1);
     }
   wait(180);
   }
    function typeA(spin){
     let way = 16;
    let v = 2.5;
    let base = rand(-180,180);
    let shotangle = rand(-180,180);
          ascent(a in 0..way){
          let radius = 0;
          let angle = base+360/way*a;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
          let color = 52;
          let delay = 0;
         Seed(x,y,v,angle,color,delay,spin,shotangle);
         }
    PlaySE(se3);
   wait(90);
        Move; 
       }

  function typeB{
     let way = 14;
    let v = [4,3,2.5,1.8];
    let base = rand(-180,180);
    let shotangle = rand(-180,180);
        ascent(b in 0..4){
          ascent(a in 0..way){
          let radius = 0;
          let angle = base+360/way*a+6.5*b;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
          let color = 52;
          let delay = 0;
         Seed(x,y,v[b],angle,color,delay,0,shotangle);
         }
       }
    PlaySE(se3);
   wait(120);
        Move; 
       }
    }

     task Move{
        let x = rand(60,100);
        let y = rand(16,16);
        let v = 2;
        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);
        }
    }
     
     task Seed(x,y,v,angle,color,delay,spin,shotangle){
            let b = Obj_Create(OBJ_SHOT);
            Obj_SetX(b,x);
            Obj_SetY(b,y);
            Obj_SetSpeed(b,v);
            Obj_SetAngle(b,angle);
            ObjShot_SetGraphic(b,color);
            ObjShot_SetDelay(b,delay);
            ObjShot_SetBombResist(b,false);
    wait(delay);
    Spin;   
          ShotG;
       task ShotG{
       let delay = 6*2;
      let angle = Obj_GetAngle(b);
       let v = 1; let accel = v/150;
       let stop = 240;
     let color = 12;
        while(!Obj_BeDeleted(b)){
       let x = Obj_GetX(b);
       let y = Obj_GetY(b);
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,0,shotangle,0,0,v,color);
         SetShotDataA(0,stop,0,NULL,0,accel,v,color);
         FireShot(0);
       shotangle += rand(5,30)*spin;
   let spin2 = 0;
     if(spin == 0){
       spin2 = (-1)^rand_int(0,1)*5;
          }
    shotangle += rand(5,20)*spin2;
       stop -= 6;
     if(stop <= 0){break;}
      wait(6);
       }
    }
     task Spin{
       loop(60){
           Obj_SetAngle(b,Obj_GetAngle(b)+spin*2);
           wait(1);
           if(Obj_BeDeleted(b)){break;}
         }
       loop(20){
           Obj_SetAngle(b,Obj_GetAngle(b)+spin/2);
           wait(1);
           if(Obj_BeDeleted(b)){break;}
         }
      loop(40){
           Obj_SetAngle(b,Obj_GetAngle(b)+spin/4);
           wait(1);
           if(Obj_BeDeleted(b)){break;}
         }
       }
   }

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