
#Title[LXXy1]
#Text[LXXy1]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    let name        = "@u炫痎Ƃv";
     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\bell01.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");
 let out = GetCommonData("TimeOut");
   @Initialize{
     if(!out){
         CutIn(KOUMA, name, "", 0, 0, 0, 0);
           if(GetPlayerType == REIMU_A){SetLife(600);}
            else{SetLife(600);}
           SetAlpha(255);
           SetTimer(60);
           SetDamageRate(20,20);
           SetScore(1000000);
           SetInvincibility(90);
           SetGraphicRect(160,200+128,224,230+128);	
           SetMovePosition02(GetCenterX,GetClipMinY+100,0);
        }	

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

    @Finalize{
        DeleteGraphic(imgBOSS);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4);
        if(!IsTimeOut && dif == 2 && !out){
                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)));
           }
       DeleteCommonData("TimeOut"); 
     }
 
     task TMain{
          yield;
       wait(120);
      SetAlpha(255);
      SetColor(255,255,255);
      Shot;
      /*  Move;*/
        Count;
        Move2;
    }

      task Shot{
        Shot1; 
      task Shot1{
       loop{
          loop(40){
          let radius = 16;
          let angle = rand(-180,180);
          let v = 10;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 155;
          let delay = 15;
         let accel = 0.05;
         let vmax = rand(0.3,5);
       let g = 90;
        P(x,y,v,angle,accel,vmax,color,delay,g);
          }
         PlaySE(se1);
       wait(60);
         } 
      }

  Shot2;
      task Shot2{
       loop{
          loop(3){
          let radius = 16;
          let angle = rand(50,70);
          let v = 5;
          let x = GetClipMinX;
          let y = rand(GetClipMinY-60,GetClipMaxY-40);
         let color = 154;
          let delay = 15;
         let accel = 0.1;
         let vmax = rand(0.8,2);
       let g = 25;
        P(x,y,v,angle,accel,vmax,color,delay,g);
          }
       wait(20);
         } 
      }

  Shot3;
      task Shot3{
     wait(10);
       loop{
          loop(3){
          let radius = 16;
          let angle = rand(110,130);
          let v = 5;
          let x = GetClipMaxX;
          let y = rand(GetClipMinY-60,GetClipMaxY-40);
         let color = 154;
          let delay = 15;
         let accel = 0.1;
         let vmax = rand(0.8,2);
       let g = 155;
        P(x,y,v,angle,accel,vmax,color,delay,g);
          }
       wait(20);
         } 
      }

    Laser1; 
    task Laser1{
      wait(300);
      let v = 10; let length = 200; let width = 20;
      let color = 71; let delay = 20;
      loop{
        let x = GetX; let y = GetY;
       ascent(a in 0..3){
          let angle = GetAngleToPlayer+15*(a-1);
        CreateLaser01(x,y,v,angle,length,width,color,delay);
               }
       ascent(a in 0..2){
          let angle = GetAngleToPlayer+10*(a-2)-30;
        CreateLaser01(x,y,v,angle,length,width,color,delay);
               }
      ascent(a in 0..2){
          let angle = GetAngleToPlayer+10*(a+1)+30;
        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 P(x,y,v,angle,accel,vmax,color,delay,g){
        let p = Obj_Create(OBJ_SHOT);
         Obj_SetX(p,x);
         Obj_SetY(p,y);
         Obj_SetSpeed(p,v);
         Obj_SetAngle(p,angle);
         ObjShot_SetGraphic(p,color);
         ObjShot_SetDelay(p,delay);
         Obj_SetAutoDelete(p,true);
         ObjShot_SetBombResist(p,false);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
     wait(delay);
       while(Obj_GetSpeed(p) >0.5){
         Obj_SetSpeed(p,Obj_GetSpeed(p)-v/10);
         wait(1);
         }
      Speed;
       task Speed{
       Obj_SetSpeed(p,0.5);
        while(Obj_GetSpeed(p) < vmax){
          Obj_SetSpeed(p,Obj_GetSpeed(p)+accel);
          wait(1);
          }
        }
      Angle;
     task Angle{
     if(Obj_GetAngle(p) > 180){
       Obj_SetAngle(p,Obj_GetAngle(p)-360);
         }
       else if(Obj_GetAngle(p) <= -180){
       Obj_SetAngle(p,Obj_GetAngle(p)+360);
         }
    while(!Obj_BeDeleted(p)){
      /* if(Obj_GetAngle(p) > 180){
       Obj_SetAngle(p,Obj_GetAngle(p)-360);
         }*/
        if(Obj_GetAngle(p) <= g-180){
       Obj_SetAngle(p,Obj_GetAngle(p)+360);
         }
        Obj_SetAngle(p,Obj_GetAngle(p)-(Obj_GetAngle(p)-g)/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;}
       }
}