
#Title[얲Xy4]
#Text[얲Xy4]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    let name        = "아@uz@WUv";
     let csd = GetCurrentScriptDirectory;
        let gx = GetX;
        let gy = GetY;
        let gspeed = GetSpeed;
        let gangle = GetAngle;     
        let arg = GetArgument;
   let imgBOSS = csd~"img\character\dot_reimu.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\bell01.wav";
   let se2 = csd~ "bgm\tm2_shoot003.wav";
   let se3 = csd~ "bgm\tm2_laser000.wav";
   let se4 = csd~ "bgm\countdown.wav";
    let effect = csd ~ "img\magic_circle\powercircle.png";
   let arrayL = [];
 let dif = GetCommonData("Dif");
   if(dif == 2){name   = "g@uF@Ԓv";}
   @Initialize{
       CutIn(KOUMA, name, "", 0, 0, 0, 0);
           if(GetPlayerType == REIMU_A){SetLife(1200);}
            else{SetLife(1200);}
           SetTimer(90);
     SetScore(15000000);
       SetDamageRate(20,5);
           SetInvincibility(120);
           SetGraphicRect(0*128,0,1*128,128);   
           SetMovePosition03(GetCenterX,GetClipMinY+120,20,5);
        SetAlpha(255);
      MagicCircle(false);
           LoadGraphic(imgBOSS);
          LoadGraphic(effect);
          LoadUserShotData(shotData);
         LoadSE(se1);LoadSE(se2);LoadSE(se3);LoadSE(se4);
           TMain;
    }

   @MainLoop{
           SetCollisionA(GetX, GetY, 24);
           SetCollisionB(GetX, GetY, 24);

         yield;
       }

   @DrawLoop{
         SetTexture(imgBOSS);  
        DrawGraphic(GetX,GetY);
     }

    @Finalize{
 SetShotAutoDeleteClip(64,64,64,64);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4);  
       if(!IsTimeOut){
                loop(125){
              CreateItem(ITEM_SCORE,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
              }
           }         
     }
 
     task TMain{
          yield;
  SetShotAutoDeleteClip(200,200,200,200);
      Circle(40);
       wait(120);
    SetGraphicRect(0*128,2*128,1*128,3*128); 
        if(dif == 1){Shot; }
     else if(dif == 2){Shot2;}
        Count;
    }

      task Shot{
    loop{
     Concentration01(60);
     wait(60);
       Shot1;
      task Shot1{
      SetGraphicRect(4*128,2*128,5*128,3*128); 
        let way = 24;
      loop(16){
       ascent(b in 0..3){
       ascent(a in 0..way){
        let x = GetX; let y = GetY;
        let v = 5-2*b; let color = 136;
         let delay = 10;
         let angle = GetAngleToPlayer+360/way*a;
         CreateShot01(x,y,v,angle,color,delay);
           }
           }
          PlaySE(se2);
          wait(5);
       }
       }
     Shot2;
      task Shot2{ 
      loop(80){
        loop(5){
        let x = GetX; let y = GetY;
        let v = rand(0.5,4.5); 
        let color = [1,8,9,16,33,40];
        let i = rand_int(0,5);
         let delay = 10;
         let angle = rand(-180,180);
         CreateShot01(x,y,v,angle,color[i],delay);
       }
          wait(1);
       }
       }
         wait(180);
       Shot3;
       task Shot3{
      SetGraphicRect(4*128,2*128,5*128,3*128); 
        let way = 8;
     ascent(c in -1..2){
       ascent(a in 0..8){
       ascent(b in 0..9){
      let angle = GetAngleToPlayer+360/way*a+10*c;
        let x = GetX+offsetX(32,angle+90+10*c); 
        let y = GetY+offsetY(32,angle+90+10*c); ;
        let v = 10-b; let color = 136;
         let delay = 10;
         P(x,y,v,angle,color,delay,-v/30);
           }
        wait(2);
           }
          PlaySE(se2);
        } 
       }
        wait(60); Move; wait(60);
       Shot4;
      task Shot4{
         SetGraphicRect(4*128,2*128,5*128,3*128); 
        let way = 8;
     descent(c in -2..1){
       ascent(a in 0..8){
       ascent(b in 0..9){
      let angle = GetAngleToPlayer+360/way*a+10*c;
        let x = GetX+offsetX(32,angle-90+10*c); 
        let y = GetY+offsetY(32,angle-90+10*c); ;
        let v = 10-b; let color = 136;
         let delay = 10;
         P(x,y,v,angle,color,delay,-v/30);
           }
        wait(2);
           }
          PlaySE(se2);
        } 
       }
        wait(120); Move; wait(180);
     }
    }

  task Shot2{
    loop{
     Concentration01(60);
     wait(60);
       Shot1; 
      task Shot1{
      SetGraphicRect(4*128,2*128,5*128,3*128); 
        let way = 24;
      loop(16){
       ascent(b in 0..4){
       ascent(a in 0..way){
        let x = GetX; let y = GetY;
        let v = 7-2*b; let color = 136;
         let delay = 10;
         let angle = GetAngleToPlayer+360/way*a;
         CreateShot01(x,y,v,angle,color,delay);
           }
           }
          PlaySE(se2);
          wait(5);
       }
       }
     Shot2; 
      task Shot2{ 
      loop(80){
        loop(6){
        let x = GetX; let y = GetY;
        let v = rand(0.5,5); 
        let color = [1,8,9,16,33,40];
        let i = rand_int(0,5);
         let delay = 10;
         let angle = rand(-180,180);
         CreateShot01(x,y,v,angle,color[i],delay);
       }
          wait(1);
       }
       }
    Shot5;
   task Shot5{
  wait(30);
   loop(180){
    let x = GetX; let y= GetY;
  let angle = rand(-180,180);
   let v = rand(2,8);
    let accel = -v/120;
   let color = 137+rand_int(0,1)*7;
   let delay = 10;
  let angle2 = 0;
 let xbase = GetX+offsetX(v*120,angle);
 let ybase = GetY+offsetY(v*120,angle);
 let xbase1 = GetX+offsetX(150,angle+60);
 let ybase1 = GetY+offsetY(150,angle+60);
 let xbase2 = GetX+offsetX(150,angle-60);
 let ybase2 = GetY+offsetY(150,angle-60);
  let spin = 0;
  if(color == 137){angle2 = atan2(ybase1-ybase,xbase1-xbase); spin = angle2-angle;}
  else if(color == 144){angle2 = atan2(ybase2-ybase,xbase2-xbase); spin = angle-angle2;}
     CreateShotA(0,x,y,delay); 
     SetShotDataA(0,0,v,angle,0,accel,0,color);
     SetShotDataA(0,180,NULL,NULL,spin/180,0.01,5,color);
     SetShotDataA(0,360,NULL,NULL,0,0.01,5,color);
     FireShot(0);
    }
   }
         wait(180);
       Shot3; 
       task Shot3{
      SetGraphicRect(4*128,2*128,5*128,3*128); 
        let way = 8;
     ascent(c in -1..2){
       ascent(a in 0..8){
  let id = rand_int(0,9);
       ascent(b in 0..9){
      let angle = GetAngleToPlayer+360/way*a+10*c;
        let x = GetX+offsetX(32,angle+90+10*c); 
        let y = GetY+offsetY(32,angle+90+10*c); ;
        let v = 10-b; let color = 136;
         let delay = 10;
     if(id >= 0 && id <= 5){P(x,y,v,angle,color,delay,-v/30);}
   else if(id >= 6 && id <= 9){P2(x,y,v,angle,color,delay,-v/30);}
           }
        wait(2);
           }
          PlaySE(se2);
        } 
       }
        wait(60); Move; wait(60);
       Shot4; 
      task Shot4{
         SetGraphicRect(4*128,2*128,5*128,3*128); 
        let way = 8;
     descent(c in -2..1){
       ascent(a in 0..8){
   let id = rand_int(0,9);
       ascent(b in 0..9){
      let angle = GetAngleToPlayer+360/way*a+10*c;
        let x = GetX+offsetX(32,angle-90+10*c); 
        let y = GetY+offsetY(32,angle-90+10*c); ;
        let v = 10-b; let color = 136;
         let delay = 10;
     if(id >= 0 && id <= 5){P(x,y,v,angle,color,delay,-v/30);}
   else if(id >= 6 && id <= 9){P2(x,y,v,angle,color,delay,-v/30);}
           }
        wait(2);
           }
          PlaySE(se2);
        } 
       }
        wait(120); Move; wait(180);
     }
    }

  task P(x,y,v,angle,color,delay,accel){
        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);
         ObjShot_SetBombResist(p,false);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
         Obj_SetAutoDelete(p,true);
       wait(delay);
        while(Obj_GetSpeed(p) > 0){
         Obj_SetSpeed(p,Obj_GetSpeed(p)+accel);
         wait(1);
         }
       Obj_SetSpeed(p,0);
        wait(30);
         ObjShot_SetGraphic(p,16);
        PlaySE(se1);
         wait(60);
         ObjShot_SetGraphic(p,129);
        Obj_SetSpeed(p,5);
        Obj_SetAngle(p,atan2(GetPlayerY-Obj_GetY(p),GetPlayerX-Obj_GetX(p)));
        wait(30);
        ObjShot_SetGraphic(p,9);
       PlaySE(se1);
        Obj_SetSpeed(p,0);
        wait(60);
        ObjShot_SetGraphic(p,135);
        Obj_SetSpeed(p,1);
        Obj_SetAngle(p,atan2(GetPlayerY-Obj_GetY(p),GetPlayerX-Obj_GetX(p)));
     }

  task P2(x,y,v,angle,color,delay,accel){
        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);
         ObjShot_SetBombResist(p,false);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
         Obj_SetAutoDelete(p,true);
       wait(delay);
        while(Obj_GetSpeed(p) > 0){
         Obj_SetSpeed(p,Obj_GetSpeed(p)+accel);
         wait(1);
         }
       Obj_SetSpeed(p,0);
        wait(30);
         ObjShot_SetGraphic(p,16);
        PlaySE(se1);
         wait(60);
         ObjShot_SetGraphic(p,129);
        Obj_SetSpeed(p,5);
        Obj_SetAngle(p,atan2(GetPlayerY-Obj_GetY(p),GetPlayerX-Obj_GetX(p)));
        wait(3);
        ObjShot_SetGraphic(p,9);
       PlaySE(se1);
        Obj_SetSpeed(p,0);
        wait(30);
        ObjShot_SetGraphic(p,135);
        Obj_SetSpeed(p,7);
        Obj_SetAngle(p,atan2(GetPlayerY-Obj_GetY(p),GetPlayerX-Obj_GetX(p)));
     }

     task Move{
        let x = rand(64,92);
        let y = rand(0,32);
        let v = 2;
        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);
      /*   loop(90){
           CreateShot01(GetX,GetY,rand(0.5,3),rand(-180,180),9,10);
           wait(1);
        }
         SetGraphicRect(0*128,2*128,1*128,3*128); */
         wait(90);
    }
       
      task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }

   task Circle(size){
           let c= Obj_Create(OBJ_EFFECT);
             Obj_SetX(c,GetX);
             Obj_SetY(c,GetY);
             Obj_SetAngle(c,0);
             ObjEffect_SetAngle(c,0,0,0);
             ObjEffect_SetTexture(c,effect);
             ObjEffect_SetRenderState(c,ADD);
             ObjEffect_SetPrimitiveType(c,PRIMITIVE_TRIANGLEFAN);
             ObjEffect_SetLayer(c,0);
             ObjEffect_CreateVertex(c,62);
             ObjEffect_SetVertexXY(c,0,0,0);
             ObjEffect_SetVertexUV(c,0,128,128);
             ObjEffect_SetVertexColor(c,0,255,255,255,255);
             ObjEffect_SetScale(c,size/10,size/10);

            ascent(let i in 0..61){
                ObjEffect_SetVertexXY(c,i+1,cos(i*6)*20,sin(i*6)*20);
                ObjEffect_SetVertexUV(c,i+1,cos(i*6)*130+130,sin(i*6)*130+130);
                ObjEffect_SetVertexColor(c,i+1,255,255,255,255);
            }
       Spin;
       Up;
     task Spin{
      let h = 0;
         loop{
            Obj_SetX(c,GetX); Obj_SetY(c,GetY);
            ObjEffect_SetAngle(c,0,0,h);
            h += 8;
            wait(1);
           }
         }
       task Up{
            loop{
             ascent(a in 0..30){
            Obj_SetX(c,GetX); Obj_SetY(c,GetY);
            ObjEffect_SetScale(c,(size+a/5)/10,(size+a/5)/10);
            wait(1);
             }
            wait(10);
             descent(a in 0..30){
            Obj_SetX(c,GetX); Obj_SetY(c,GetY);
            ObjEffect_SetScale(c,(size+a/5)/10,(size+a/5)/10);
            wait(1);
             }
            wait(10);
           }
        }
    }

     function pray(m ,n){
    loop(m){
       SetGraphicRect(6*128,0*128,7*128,1*128); 
       wait(n);
       SetGraphicRect(7*128,0*128,8*128,1*128); 
       wait(n);
       SetGraphicRect(6*128,1*128,7*128,2*128); 
       wait(n);
       SetGraphicRect(7*128,1*128,8*128,2*128); 
       wait(n);
       SetGraphicRect(6*128,2*128,7*128,3*128); 
       wait(n);
       SetGraphicRect(7*128,2*128,8*128,3*128); 
        wait(n);
       SetGraphicRect(6*128,3*128,7*128,4*128); 
       wait(n);
       SetGraphicRect(7*128,3*128,8*128,4*128); 
       wait(n);
       }
     }

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

     function enemy(text,x,y,speed,angle,arg){
               CreateEnemyFromFile(text,x,y,speed,angle,arg);
            }
}