
#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\dot-kaze-ti2.png";
   let wIni  = 120;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\tm2_shoot000.wav";
   let se2 = csd~ "bgm\tm2_laser000.wav";
   let se3 = csd~ "bgm\concentration.wav";
   let se4 = csd~ "bgm\countdown.wav";
   let arrayL = [];
 let dif = GetCommonData("Dif");
   @Initialize{
           SetAlpha(0);
           SetColor(255,0,255);
           SetLife(2000);
           SetTimer(40);
           SetDamageRate(100,100);
    /* if(dif == 2){SetDamageRate(100,5);}*/
           SetInvincibility(wIni);
           SetGraphicRect(160,200,224,230);	

           LoadGraphic(imgBOSS);
          /* SetTexture(imgBOSS); */
          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{
     SetCommonData("TimeOut",IsTimeOut);
        DeleteGraphic(imgBOSS);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4);
        if(!IsTimeOut && dif == 1){
                loop(32){
              CreateItem(ITEM_SCORE,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,16),rand(-180,180)));
              }
              CreateItem(ITEM_BOMB,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,16),rand(-180,180)));
           }
       else if(IsTimeOut && dif == 1){
     let n = 128;
          loop(n){
          let radius = rand(0,128);
          let angle = rand(-180,180);
          let v = 0;
          let x = GetX+4*offsetX(radius,angle);
          let y = GetY+1/4*offsetY(radius,angle);
         let color = 40;
          let delay = 0;
         let accel = 0.05;
         let vmax = rand(0.05,5);
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,90,0,0,v,color);
         SetShotDataA(0,120,NULL,90,0,accel,vmax,color);
         FireShot(0);
         PlaySE(se1);
       wait(1);
        }
     }           
     }
 
     task TMain{
          yield;
       Concentration01(120);
       wait(120);
      SetAlpha(255);
      SetColor(255,255,255);
        if(dif == 1){Shot;}
       else if(dif == 2){Shot2;}
        Move;
        Count;
        Move2;
    }

      task Shot{
        Shot1;
      task Shot1{
       loop{
          let radius = rand(0,64);
          let angle = rand(-180,180);
          let v = 0;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 40;
          let delay = 0;
         let accel = 0.05;
         let vmax = rand(0.3,5);
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,90,0,0,v,color);
         SetShotDataA(0,120,NULL,90,0,accel,vmax,color);
         FireShot(0);
         PlaySE(se1);
       wait(10);
         } 
      }
    Laser1;
    task Laser1{
      wait(300);
      let v = 5; let length = 200; let width = 50;
      let color = 71; let delay = 20;
      loop{
        let x = GetX; let y = GetY;
       ascent(a in 0..3){
          let angle = GetAngleToPlayer+30*(a-1);
        CreateLaser01(x,y,v,angle,length,width,color,delay);
               }
           PlaySE(se2);
         wait(150);
          }
        }
    }

  task Shot2{
        Shot1;
      task Shot1{
       loop{
          let radius = rand(0,64);
          let angle = rand(-180,180);
          let v = rand(4,5);
          let x = GetCenterX+rand(-250,250);
          let y = GetClipMinY+rand(-30,150);
         let color = 55;
          let delay = 10;
         let accel = -0.03;
         let vmax = rand(0.2,0.2);
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,90,0,accel,vmax,color);
        /* SetShotDataA(0,120,NULL,90,0,accel,vmax,color);*/
         FireShot(0);
         PlaySE(se1);
       wait(6);
         } 
      }
   /* Laser1;*/
    task Laser1{
      wait(180);
      let v = 10; let length = 300; let width = 100;
      let color = 71; let delay = 20;
      loop{
        let x = GetX; let y = GetY;
       ascent(a in 0..3){
          let angle = GetAngleToPlayer+30*(a-1);
        CreateLaser01(x,y,v,angle,length,width,color,delay);
               }
           PlaySE(se2);
         wait(150);
          }
        }
    }

     task Move{
       wait(30);
      loop{
        let x = rand(GetClipMinX+32,GetClipMaxX-32);
        let y = rand(GetClipMinY+32,GetClipMinY+120);
        if(GetX >= x){SetGraphicRect(160,200,224,230);}
        else if(GetX < x){SetGraphicRect(160,200,224,230);}
         SetMovePosition01(x,y,1);
        wait(120);
         }
    }
       
      task Move2{
           loop{
            ascent(a in 0..10){
              SetGraphicAngle(0,0,6*a);
             wait(1);
               }
             ascent(a in 0..20){
              SetGraphicAngle(0,0,60-6*a);
             wait(1);
               }
           ascent(a in 0..10){
              SetGraphicAngle(0,0,6*a-60);
             wait(1);
               }
            }
        }

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