
#Title[ルーミア通常弾幕1]
#Text[ルーミア通常弾幕1]
#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_coin000.wav";
   let se3 = csd~ "bgm\concentration.wav";
   let se4 = csd~ "bgm\countdown.wav";
   let arrayL = [];
let dif = GetCommonData("Dif");
   @Initialize{
           SetColor(0,0,0);
           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);
    SetEffectForZeroLife(1,0,0);
           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(40){
              CreateItem(ITEM_SCORE,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,16),rand(-180,180)));
              }
           }
     }
 
     task TMain{
          yield;

    if(dif == 1){ Shot;}
   else if(dif == 2){Shot2;}
        Move;
        Count;
    }

      task Shot{
       loop{
       loop(4){
          let x = GetX; let y = GetY;
      let v = 3;
        let accel = -0.02;
         ascent(a in 0..6){
       ascent(b in 0..8){
    let base = rand(-180,180);
      let angle = base+60*a;
       let color = 25+2*b;
         let delay = 10*(b+1);
         let vmin =  0.1+b/8;
          CreateShot02(x,y,v,angle,accel,vmin,color,delay);
            }
           }
      PlaySE(se1);
         wait(30);
         }
        wait(180);
        }
    }

  task Shot2{
   loop{
    loop(108){
    let x = GetX; let y = GetY;
    let delay = 30; let v = rand(1,6);
    let angle = rand(-180,180);
   let color = rand_int(1,48);
     CreateShotA(0,x,y,delay); 
     SetShotDataA(0,0,v,angle,0,-v/180,0,color);
     SetShotDataA(0,300,0,rand(-180,180),0,0.02,2,color);
     FireShot(0);
         PlaySE(se1);
         }
     wait(100);
       }
    }

     task Move{
      loop{
        wait(30);
        let x = rand(GetClipMinX+32,GetClipMaxX-32);
        let y = rand(GetClipMinY+32,GetClipMinY+120);
        if(GetX >= x){SetGraphicRect(128,1,192,64);}
        else if(GetX < x){SetGraphicRect(192,1,256,64);}
         SetMovePosition02(x,y,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;}
       }
}