
#Title[パルスィスペル3]
#Text[パルスィスペル3]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
   #include_script".\function_bullet.txt"
     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\dot-kaze-ti2.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\bell01.wav";
   let se2 = csd~ "bgm\tm2_coin000.wav";
   let se3 = csd~ "bgm\fire01.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(1300);}
            else{SetLife(1300);}
           SetTimer(60);
           SetDamageRate(40,30);
   /*  if(dif == 2){SetDamageRate(40,0);}*/
           SetScore(2000000);
           SetInvincibility(180);
           SetGraphicRect(64,1,128,64);
           SetMovePosition03(GetCenterX,GetClipMinY+100,10,5);	

           LoadGraphic(imgBOSS);
           SetTexture(imgBOSS); 
          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{  
        DrawGraphic(GetX,GetY);
     }

    @Finalize{
        DeleteGraphic(imgBOSS);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4); 
        if(!IsTimeOut){
                loop(54){
              CreateItem(ITEM_SCORE,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
              }
           }  
        SetShotColor(255,255,255);        
     }
 
     task TMain{
          yield;
       wait(120);
        if(dif == 1){Shot;}
     else if(dif == 2){Shot2;}  
        Count;
    }

      task Shot{
       ascent(a in 0..18){
           let radius = 32;
          let angle = GetAngleToPlayer+10+a*20;
          let v = 4;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 52;
          let delay = 30;
         CreateShot01(x,y,v,angle,color,delay);
        }
    SetShotColor(64,255,64);
       ascent(a in 0..36){
          let radius = 16;
          let angle = GetAngleToPlayer+a*10;
          let v = 2;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 52;
          let delay = 10;
         CreateShot01(x,y,v,angle,color,delay);
        }
       wait(60);
        PlaySE(se2);
        PlaySE(se1);
        wait(60); 
      loop{
         Move(1.2);
        loop(90){
          let radius = 16;
          let angle = GetAngleToPlayer+rand(-60,60);
          let v = rand(0.5,2);
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 28/*241*/;
          let delay = 20;
         CreateShot01(x,y,v,angle,color,delay);
         wait(1);
         PlaySE(se3);
        }
       wait(150);
      ascent(b in 0..21){
         ascent(a in 0..3){
           let radius = 0;
          let angle = GetAngleToPlayer+(90-4*b)*(a-1);
          let v = 6;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 188;
          let delay = 10;
      let length = 400; let width = 10;
        CreateLaser01(x,y,v,angle,length,width,color,delay);
        }
        Move(5);
       PlaySE(se2);
        PlaySE(se1);
         wait(5);
       }
       wait(30);
        }
    }

 task Shot2{
    SetShotColor(64,255,64);
  let way = 36;
  let yuyu = rand(-360/way,360/way);
    ascent(b in 0..6){
       ascent(a in 0..way){
          let radius = 16;
          let angle = GetAngleToPlayer+a*360/way+yuyu;
          let v = 1.5;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 52;
          let delay = 10;
        let vmax = v+b;
    let accel = 1;
        CreateShotA(0,x,y,delay); 
        SetShotDataA(0,0,v,angle,0,0,v,color);
        SetShotDataA(0,60,NULL,NULL,0,accel,vmax,color);
        FireShot(0);
        }
       }
       wait(60);
        PlaySE(se2);
        PlaySE(se1);
        wait(60); 
      loop{
         Move(1.2);
        loop(90){
         loop(3){
          let radius = 16;
          let angle = GetAngleToPlayer+rand(-60,60);
          let v = rand(0.1,4);
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 241;
          let delay = 20;
         CreateShot01(x,y,v,angle,color,delay);
       let radius = 16;
          let angle = rand(-180,0);
          let v = rand(0.1,4);
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 241+1;
          let delay = 20;
      let accel = rand(0.01,0.03);
    let grvAngle = 90;
      GravityShot(x,y,v,angle,accel,grvAngle,color,delay);
          }
         wait(1);
         PlaySE(se3);
        }
       wait(180);
      ascent(b in 0..10){
         ascent(a in 0..9){
           let radius = 0;
          let angle = GetAngleToPlayer+20*(a-4);
          let v = 6;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 52;
          let delay = 10;
       CreateShot01(x,y,v,angle,color,delay);
        }
        Move(5);
       PlaySE(se2);
        PlaySE(se1);
         wait(15);
       }
       wait(30);
        }
    }

     task Move(v){ 
        let x = rand(GetClipMinX+60,GetClipMaxX-60);
        let y = rand(GetClipMinY+32,GetCenterY);
     if(dif == 2){
        y = rand(GetClipMinY+32,GetClipMinY+150);
        }
        SetMovePosition03(x,y,20,v);
    }
       
      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;}
       }
}