
#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\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");
if(dif == 2){
 name   = "闇符　「フォルスディマーケィション」";
  }
   @Initialize{
        CutIn(KOUMA, name, "", 0, 0, 0, 0);
           if(GetPlayerType == REIMU_A){SetLife(1000);}
            else{SetLife(1000);}
           SetTimer(60);
           SetScore(2000000);
           SetDamageRate(30,45);
   /*    if(dif == 2){SetDamageRate(30,0);}*/
           SetInvincibility(wIni);
           SetGraphicRect(1,1,64,64);
           SetMovePosition02(GetCenterX,GetClipMinY+90,120);	

           LoadGraphic(imgBOSS);
          /* SetTexture(imgBOSS); */
           setGraphicStop;
          LoadUserShotData(shotData);
         LoadSE(se1);LoadSE(se2);LoadSE(se3);LoadSE(se4);
    SetEffectForZeroLife(60,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(48){
              CreateItem(ITEM_SCORE,GetX+offsetX(rand(32,64),rand(-180,180)),GetY+offsetY(rand(32,64),rand(-180,180)));
              }
           }
     }
 
     task TMain{
          yield;
          wait(120);
    SetGraphicRect(64,1,128,64);
       if(dif == 1){Shot;}
      else if(dif == 2){Shot2;}
        Count;
    }

      task Shot{
     wait(60);
         loop{
      ascent(t in 0..3){
        ascent(i in 0..36+6*t){  
          let angle = i*360/(36+6*t)+GetAngleToPlayer;
          let x = GetX+80+offsetX(0,angle);
          let x2 = GetX-80+offsetX(0,angle);
          let y = GetY+30+offsetY(0,angle);
          let v = 5;
          let color = 65+2.5*t;
          let delay = 10;
          let d = (-1)^i*60;
          Bullet(x,y,v,angle,color,delay,d);
          Bullet(x2,y,v,angle,color,delay,d);
         PlaySE(se1);
      }     
       wait(60);
        }
    let angle = GetAngleToPlayer;
      ascent(v in 0..20){
        CreateShot01(GetX,GetY,0.5+v/4,angle,31,40);
        CreateShot01(GetX,GetY,0.5+v/2,angle-30,31,60);
        CreateShot01(GetX,GetY,0.5+v/2,angle+30,31,60);
        CreateShot01(GetX,GetY,0.5+v/4,angle-40,31,20);
        CreateShot01(GetX,GetY,0.5+v/4,angle+40,31,20);
       PlaySE(se2);
             }
       wait(240);
        }
    }

 task Shot2{
         loop{
      ascent(t in 0..3){
       let way = 48+12*t;
        ascent(i in 0..way){  
          let angle = i*360/way+GetAngleToPlayer;
          let x = GetClipMinX;
          let x2 = GetClipMaxX;
         let y = GetClipMinY;
          let y2 = GetClipMaxY;
          let v = 5.5;
          let color = 65+2.5*t+8;
          let delay = 10;
          let d = (-1)^i*60;
          Bullet(x,y,v,angle,color,delay,d);
          Bullet(x2,y,v,angle,color,delay,d);
          Bullet(x,y2,v,angle,color,delay,d);
          Bullet(x2,y2,v,angle,color,delay,d);
      }    
   PlaySE(se1);
   wait(60); 
    }
  /*  let angle = GetAngleToPlayer;
      ascent(v in 0..20){
       ascent(a in 0..5){
        CreateShot01(GetX,GetY,0.5+v/2,angle,31,30);
        CreateShot01(GetX,GetY,0.5+v/4,angle-3*(a+1)-0,31,60);
        CreateShot01(GetX,GetY,0.5+v/4,angle+3*(a+1)+0,31,60);
        CreateShot01(GetX,GetY,0.5+v/2,angle-5*(a+1),31,30);
        CreateShot01(GetX,GetY,0.5+v/2,angle+5*(a+1),31,30);
        }
             }  */
   PlaySE(se2);  
  
 ascent(a in 0..6){
  let x = GetX+30*(-1)^a;
  let y = GetY+5;
  let length = 500; let width = 15;
  let color = 16; let delay = 90;
   let angle = GetAngleToPlayer;
  let kill = 150;
   CreateLaserA(0,x,y,length,width,color,delay);
     SetLaserDataA(0,0,angle,0,0,0,0);
     SetShotKillTime(0,delay+kill);
     FireShot(0);
    wait(10);
       }
       wait(190);
        }
    }

    task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }
            
    task Bullet(x,y,v,angle,color,delay,d){
            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);

        while(Obj_GetSpeed(b)>0){
               Obj_SetSpeed(b,Obj_GetSpeed(b)-0.09);
             wait(1);
              }
      Obj_SetSpeed(b,0);
         wait(120);
         Obj_SetAngle(b,Obj_GetAngle(b)+d);
         Obj_SetSpeed(b,1.5);
   }

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