
#Title[大妖精通常弾幕3]
#Text[大妖精通常弾幕3]
#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\dot_daiyousei.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\arrow01.wav";
   let se2 = csd~ "bgm\eco00.wav";
   let se3 = csd~ "bgm\concentration.wav";
   let se4 = csd~ "bgm\countdown.wav";
    let effect = csd ~ "img\magic_circle\powercircle.png";
   let arrayL = [];
 let dif = GetCommonData("Dif");
 let out = GetCommonData("TimeOut");
   @Initialize{
      if(!out){
           if(GetPlayerType == REIMU_A){SetLife(2000);}
            else{SetLife(2000);}
           SetTimer(45);
       SetDamageRate(100,50);
       }
           SetInvincibility(120);
           SetGraphicRect(0*128,0*128,1*128,1*128);   
           SetMovePosition03(GetCenterX,GetClipMinY+100,20,5);
        SetAlpha(255);
           LoadGraphic(imgBOSS);
          LoadGraphic(effect);
          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);
        DeleteGraphic(effect);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4); 
       CreateItem(ITEM_BOMB,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));  
         if(!IsTimeOut && !out){
                loop(30){
              CreateItem(ITEM_SCORE,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
              }  
    CreateItem(ITEM_BOMB,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
           }    
      DeleteCommonData("TimeOut");        
     }
 
     task TMain{
          yield;
     Concentration01(90);
     PlaySE(se2);
       wait(90);
        if(dif == 1){Shot;}
     else if(dif == 2){Shot2;}
        Count;
    }

      task Shot{
       let radius = 0;
      let c = [169,174];
      let vir = [1,2,3,4,5];
      let delay = 0;
      let accel = 0;
       loop{
       let base = rand(-180,180);
        ascent(a in 0..120){
           ascent(b in 0..4){
          ascent(d in 0..2){
           let radius = 0;
          let angle = base+5*a+90*b;
          let v = 4-d*2;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = c[1];
          let delay = 0;
         let accel = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,accel,v,color);
         FireShot(0);
         PlaySE(se1);  
          }
       }
       wait(1);
        }
       move;
      wait(120);
      SetGraphicRect(0*128,0*128,1*128,1*128);   
      base = rand(-180,180);
       ascent(a in 0..120){
           ascent(b in 0..4){
          ascent(d in 0..2){
           let radius = 0;
          let angle = base-5*a+90*b;
          let v = 4-d*2;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = c[0];
          let delay = 0;
         let accel = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,accel,v,color);
         FireShot(0);
         PlaySE(se1);  
          }
       }
       wait(1);
        }
         wait(120);
      }
    }

  task Shot2{
       let radius = 0;
      let c = [169,174];
      let vir = [1,2,3,4,5];
      let delay = 0;
      let accel = 0;
       loop{
       let base = rand(-180,180);
        ascent(a in 0..120){
           ascent(b in 0..4){
          ascent(d in 0..2){
           let radius = 0;
          let angle = base+5*a+90*b;
          let v = 7-d*2;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = c[1];
          let delay = 0;
         let accel = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,accel,v,color);
         FireShot(0);
         PlaySE(se1);  
          }
       }
       wait(1);
        }
       move;
      wait(120);
      SetGraphicRect(0*128,0*128,1*128,1*128);   
      base = rand(-180,180);
       ascent(a in 0..120){
           ascent(b in 0..4){
          ascent(d in 0..2){
           let radius = 0;
          let angle = base-5*a+90*b;
          let v = 7-d*2;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = c[0];
          let delay = 0;
         let accel = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,accel,v,color);
         FireShot(0);
         PlaySE(se1);  
          }
       }
       wait(1);
        }
         wait(120);
      }
    }

     function move{
        let x = rand(128,200);
        let y = rand(32,64);
        let v = 5;
        let xmin = GetClipMinX+64;
        let ymin = GetClipMinY+60;
        let xmax = GetClipMaxX-64;
        let ymax = GetCenterY-60;
        if(x>=GetX){SetGraphicRect(2*128,3*128,3*128,4*128);}
       else if(x<=GetX){SetGraphicRect(2*128,1*128,3*128,2*128);}
         SetMovePositionRandom01(x,y,v,xmin,ymin,xmax,ymax);
    }
       
      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 sc(r,g,b){
             SetShotColor(r,g,b);
     }

       sub setGraphicStop  { SetGraphicRect( 1, 1, 64, 64); }

       function wait(w){
                loop(w){yield;}
       }
}