
#Title[Xy1]
#Text[Xy1]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
     let name        = "@u̑v";
     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\water07.wav";
   let se2 = csd~ "bgm\tm2_coin000.wav";
   let se3 = csd~ "bgm\buble03.wav";
   let se4 = csd~ "bgm\countdown.wav";
   let arrayL = [];
 let dif = GetCommonData("Dif");
 if(dif == 2){ name  = "@u̑ -Lunatic-v";}
   @Initialize{
         CutIn(KOUMA, name, "", 0, 0, 0, 0);
           if(GetPlayerType == REIMU_A){SetLife(1400);}
            else{SetLife(1400);}
           SetAlpha(255);
           SetTimer(60);
           SetDamageRate(50,40);
           SetScore(1000000);
           SetInvincibility(60);
           SetGraphicRect(128,64,192,128);
           SetMovePosition02(GetCenterX,GetClipMinY+100,0);	

           LoadGraphic(imgBOSS);
           SetTexture(imgBOSS); 
          LoadUserShotData(shotData);
         LoadSE(se1);LoadSE(se2);LoadSE(se3);LoadSE(se4);
   SetEffectForZeroLife(1,0,0);
           TMain;
    }

   @MainLoop{
           SetCollisionA(GetX, GetY, 24);
           SetCollisionB(GetX, GetY, 24);

         yield;
       }

   @DrawLoop{ 
        DrawGraphic(GetX,GetY);
     }

    @Finalize{
        DeleteGraphic(imgBOSS);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4);
        if(!IsTimeOut){
            CreateItem(ITEM_1UP,GetX,GetY);
          }
     }
 
     task TMain{
          yield;
       wait(60);
     /*   if(dif == 1){Shot;}
     else if(dif == 2){Shot2;} 
        Move; */
        Count;
        Waterfall;
    }

      task Shot{
     wait(60);
       loop{
           let radius = rand(0,92);
          let angle = 90;
          let angle2 = rand(-180,180);
          let v = rand(0.5,3);
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 49;
         let color2 = 25;
          let delay = 10;
         CreateShot01(x,y,v,angle,color,delay);
       ascent(a in 0..36){
        let v = rand(0.5,2.5);
         CreateShot01(x,y,v,angle2+30*a,color2,delay);
         }
       /* PlaySE(se3);*/
         wait(40);
        }
    }

 task Shot2{
     wait(60);
       loop{
           let radius = rand(0,64);
          let angle = 90;
          let angle2 = rand(-180,180);
          let v = rand(0.5,4);
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 56;
         let color2 = 48;
          let delay = 10;
       ascent(a in 0..3){
         CreateShot01(x,y,v,angle+60*(a-1),color,delay);
       }
       ascent(a in 0..36){
        let v = rand(0.5,4);
         CreateShot01(x,y,v,rand(0,180),color2,delay);
         }
       /* PlaySE(se3);*/
         wait(45);
        }
    }

     task Move{
         wait(30);
       let x = GetCenterX;
       let y = GetClipMinY+100;
       let radius = 64;
       let angle = -180;
     loop{
       SetX(x+offsetX(radius,angle/2)*2);
       SetY(y+offsetY(radius,angle*2));
       angle += 1;
       wait(1);
        }
    }
       
      task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }
     
     task Waterfall{
          wait(60);
         loop{
             let x = rand(GetClipMinX,GetClipMaxX);
             let y = GetClipMinY;
             let angle = 90;
             let v = rand(4,8);
             let color = [8,16,24,32,40,48,152];
             let i = rand_int(0,6);
              let delay = rand(10,120);
             let n = rand(10,40);
        let k = rand(0,3);
    if(dif == 2){k = rand(0,6);}
           Water(x,y,v,angle,color[i],delay,n,k);
           wait(1);
           PlaySE(se1);
           }
       }
     task Water(x,y,v,angle,color,delay,n,k){
            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(delay+n);
    if(k >= 2 && !Obj_BeDeleted(b)){
       CreateShot01(Obj_GetX(b),Obj_GetY(b),k,90,color,20);
      }
            ObjShot_FadeDelete(b);
        /*  Obj_SetSpeed(b,0);*/
       }

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