
#Title[ルーミア通常弾幕2]
#Text[ルーミア通常弾幕2]
#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\ExRumia.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\tm2_shoot000.wav";
   let se2 = csd~ "bgm\tm2_switch001.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(2000);}
            else{SetLife(2000);}
           SetTimer(60);
           SetDamageRate(100,100);
     /*  if(dif == 2){SetDamageRate(100,5);}*/
           SetInvincibility(wIni);
           SetGraphicRect(1,1,64,64);	
           LoadGraphic(imgBOSS);
          /* SetTexture(imgBOSS); */
           setGraphicStop;
          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{
        DeleteGraphic(imgBOSS);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4);
     }
 
     task TMain{
          yield;
    SetTexture(imgBOSS);
     if(dif == 1){ Shot;}
    if(dif == 2){Shot2;}
        Count;
    }

      task Shot{
       loop{
          let angle = GetAngleToPlayer-138;
         let angle2 = GetAngleToPlayer+138;
          loop(3){
          let v = 0.5;
            loop(30){
          let x = GetX+offsetX(32,angle);
          let y = GetY+offsetY(32,angle);
          let x2 = GetX+offsetX(32,angle2);
          let y2 = GetY+offsetY(32,angle2);
         let color = 28;
          let delay = 30;
         CreateShot01(x,y,v,angle,color,delay);
         CreateShot01(x2,y2,v,angle2,color+1,delay);
         angle += 8;
         angle2 -= 8;
         v += 0.1;
         PlaySE(se1);
         wait(1);
           }
        angle += 5;
        angle2 -= 5;
       }
       wait(120);
       Move;
     }
    }

 task Shot2{
       loop{
          let angle = GetAngleToPlayer-138;
         let angle2 = GetAngleToPlayer+138;
          loop(3){
            loop(30){
   let v = 1;
    ascent(a in 0..3){
          let v2 = v+a;
          let x = GetX+offsetX(32,angle);
          let y = GetY+offsetY(32,angle);
          let x2 = GetX+offsetX(32,angle2);
          let y2 = GetY+offsetY(32,angle2);
         let color = 28;
          let delay = 10;
         CreateShot01(x,y,v2,angle,color,delay);
         CreateShot01(x2,y2,v2,angle2,color+1,delay);
         angle += 12;
         angle2 -= 12;
       }
         v += 0.1;
       PlaySE(se1);
         wait(1);
        }
        angle += 7;
        angle2 -= 7;
       }
       wait(180);
       Move;
     }
    }


     task Move{
        let x = rand(48,100);
        let y = rand(0,32);
        let v = 2;
        let xmin = GetClipMinX+96;
        let ymin = GetClipMinY+60;
        let xmax = GetClipMaxX-96;
        let ymax = GetCenterY-60;
    /*    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); */
        wait(120);
       let angle = GetAngleToPlayer;
   if(dif == 1){
     ascent(v in 0..5){
        CreateShot01(GetX,GetY,0.5+v,angle,30,20);
        CreateShot01(GetX,GetY,0.5+v,angle-20,30,40);
        CreateShot01(GetX,GetY,0.5+v,angle+20,30,40);
       PlaySE(se2);
         }
       }
   else if(dif == 2){
      ascent(v in 0..5){
       ascent(a in 0..5){
        CreateShot01(GetX,GetY,0.5+v,angle,30,10);
        CreateShot01(GetX,GetY,0.5+v,angle-3*(a+1),30,20+10*a);
        CreateShot01(GetX,GetY,0.5+v,angle+3*(a+1),30,20+10*a);
         }
         }
     PlaySE(se2);
       }
    }
            
     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;}
       }
}