
#Title[ʏe1]
#Text[ʏ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_shoot003.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(10);}
            else{SetLife(10);}
           SetTimer(60);
           SetDamageRate(0,0);
           SetInvincibility(150);
           SetGraphicRect(128,64,192,128);
           SetMovePosition03(GetCenterX,GetClipMinY+100,20,5);	

           LoadGraphic(imgBOSS);
          /* SetTexture(imgBOSS); */
          LoadUserShotData(shotData);
         LoadSE(se1);LoadSE(se2);LoadSE(se3);LoadSE(se4);
        SetAlpha(64);
           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);           
     }
 
     task TMain{
          yield;
       wait(180);
    Shot;
        Move;
      /*  Count;*/
    }

      task Shot{
     let n = 120;
    loop{
       loop(6){
           let radius = 0;
          let angle = GetAngleToPlayer;
          let v = 0;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 39;
         let delay = 20;
         Bullet(x,y,v,angle,color,delay);
         wait(n);
         }
       n -= 10;
       if(n < 10){n = 10;}
       }
    }

     task Move{
         wait(30);
       let x = GetCenterX;
       let y = GetClipMinY+120;
       let radius = 64;
       let angle = -90;
     loop{
       SetX(x+offsetX(radius,angle)*2);
       SetY(y+offsetY(radius,angle));
       angle += 1;
       wait(1);
        }
    }
       
      task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }
     
     task Bullet(x,y,v,angle,color,delay){
            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);
        wait(90);
      let color2 = 151;
       let delay2 = 20;
   let ss = (-1)^rand_int(0,1);
  if(Obj_GetX(b) >= GetCenterX){ss = -1;}
  else if(Obj_GetX(b) < GetCenterX){ss = 1;}
    if(dif == 1 && !Obj_BeDeleted(b)){
      ascent(a in 0..5){
        CreateShot01(Obj_GetX(b),Obj_GetY(b),2,Obj_GetAngle(b)-40+20*a,color2,delay2);
        }
      }
   else if(dif == 2 && !Obj_BeDeleted(b)){
        ascent(a in 0..12){
        CreateShot01(Obj_GetX(b),Obj_GetY(b),2,Obj_GetAngle(b)+10*a*ss,color2-96,delay2+10*a);
        }
      }
        PlaySE(se2);
       Obj_Delete(b);
    }

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