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

script_enemy_main{
    let name        = "E@u_Ɛ̋Yv";
     let csd = GetCurrentScriptDirectory;
        let gx = GetX;
        let gy = GetY;
        let gspeed = GetSpeed;
        let gangle = GetAngle;     
        let arg = GetArgument;
   let imgBOSS = csd~"img\character\dot_yukari.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\bell01.wav";
   let se2 = csd~ "bgm\eco02_a.wav";
   let se3 = csd~ "bgm\cursor02.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   = "E@u_Ɛ̋Y -Lunatic-v";}
   @Initialize{
       CutIn(KOUMA, name, "", 0, 0, 0, 0);
           if(GetPlayerType == REIMU_A){SetLife(1000);}
            else{SetLife(1000);}
           SetTimer(75);
     SetScore(6000000);
       SetDamageRate(20,12);
           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{
        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;
      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{
      let way = 150; 
    Bullet;  
   task Bullet{
   loop{
       let x = GetX; let y = GetY;
       let v = 0.6;  let color = 47; let delay = 0;
       ascent(a in 0..way){
        let angle = GetAngleToPlayer+360/way*a;
        P(x,y,v,angle,color,delay,0);
     }
       PlaySE(se1);
       wait(180); 
   }
  }
    Laser; 
    task Laser{
      let way = 8;
       loop{
         loop(6){
          let x = GetX; let y = GetY;
       let v = 2;  let color = 47; let delay = 0;
      let width = 8; let length = 120;
      ascent(a in 0..way){
        let angle = GetAngleToPlayer+360/way*a;
       L(x,y,v,angle,length,width,color,0);
       }
      wait(60);
       }
      PlaySE(se3);
       TimeStop(300,0,0,1);
     wait(300);
    PlaySE(se3);
  /*   let n = 6; 
     loop(n){
         PlaySE(se3);
         wait(300/n);
        }  */
       wait(1);
      }
      }
    }

 task Shot2{
      let way = 150; 
  /*  Bullet; */
   task Bullet{
   loop{
       let x = GetX; let y = GetY;
       let v = 0.6;  let color = 47; let delay = 0;
       ascent(a in 0..way){
        let angle = GetAngleToPlayer+360/way*a;
        P2(x,y,v,angle,color,delay,0,GetX,GetY);
     }
       PlaySE(se1);
       wait(180); 
   }
  }
    Laser; 
    task Laser{
      let way = 8;
     let radius = 0;
       loop{
         loop(6){
       let v = 2;  let color = 47; let delay = 60;
      let width = 8; let length = 120;
      ascent(a in 0..way){
        let angle = GetAngleToPlayer+360/way*a;
    let x = GetPlayerX/*+offsetX(radius,angle)*/; 
    let y = GetPlayerY/*+offsetY(radius,angle)*/; 
   if(x <= GetClipMinX+60){x = GetClipMinX+60;}
   if(y >= GetClipMaxY-60){y = GetClipMaxY-60;}
       L2(x,y,v,angle,length,width,color,delay,0);
  L(GetX,GetY,v,angle,length,width,color,0);
       }
   wait(60);
       }
   PlaySE(se3);
       TimeStop(300,0,0,1);
    wait(300);
   PlaySE(se3);
   /*  let n = 6; 
     loop(n){
         PlaySE(se3);
         wait(300/n);
        }   */
       wait(1);
      }
      }
    }

     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);
         wait(90);
         SetGraphicRect(0*128,2*128,1*128,3*128); 
         wait(90);
    }
       
      task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }
     
   task P(x,y,v,angle,color,delay,id){
        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,true);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
      Obj_SetAutoDelete(p,false);
   wait(delay);
     if(id == 0){
    Obj_SetAutoDelete(p,true);
        Plot;
       task Plot{
        let fam = rand(0,3);
          while(!Obj_BeDeleted(p)){
             if(IsBGStopping){
       if(fam >= 1){
               ObjShot_SetGraphic(p,color-40);
           }
       else if(fam < 1){ObjShot_SetGraphic(p,255);}
              Obj_SetSpeed(p,v/5);
             }
            else{ObjShot_SetGraphic(p,color); Obj_SetSpeed(p,v);}
            wait(1);
            }
         }
       }
     else if(id >=1 && id <= 12){
      Obj_SetAutoDelete(p,false);
        Spin;
        task Spin{
        function set_xy(radius,an){
             Obj_SetAngle(p,Obj_GetAngle(p)+an);   
             Obj_SetX(p,GetX+offsetX(radius,Obj_GetAngle(p)));
             Obj_SetY(p,GetY+offsetY(radius,Obj_GetAngle(p)));
            }
       let n = (22.5+45*2)/290;
         let radius = ((Obj_GetX(p)-GetX)^2+(Obj_GetY(p)-GetY)^2)^0.5;
            while(!Obj_BeDeleted(p)){
             if(IsBGStopping){
            set_xy(radius,(-1)^id*n);
            wait(1);
             }
         else if(!IsBGStopping && id != 1){Obj_Delete(p);}
         else if(!IsBGStopping && id == 1){
         let x = Obj_GetX(p);
             let y = Obj_GetY(p);
       let v = 2;  let color = 47; let delay = 0;
      let width = 8; let length = 120;
     let angle = Obj_GetAngle(p);
   /*   L(x,y,v,angle,length,width,color,1);*/
  LL(x,y,v,angle,length,width,color,delay);
           wait(1);
          Obj_Delete(p);
               }
             }
           }
       }
          Del;
        task Del{
           while(!Obj_BeDeleted(p)){ 
          let radius = ((Obj_GetX(p)-GetX)^2+(Obj_GetY(p)-GetY)^2)^0.5;
              if(radius >= 360){
               Obj_Delete(p);
                }
             wait(1);
             }
          }
     }        

  task L(x,y,v,angle,length,width,color,id){
              let l = Obj_Create(OBJ_LASER);
              arrayL = arrayL ~ [l];
              Obj_SetX(l,x);
              Obj_SetY(l,y);
              Obj_SetAngle(l,angle);
              ObjShot_SetGraphic(l,color);
              Obj_SetCollisionToObject(l,true);
              Obj_SetCollisionToPlayer(l,true);
              ObjLaser_SetLength(l,0); 
              ObjLaser_SetWidth(l,width);
              ObjLaser_SetSource(l,false);
         Obj_SetAutoDelete(l,false);
      if(id == 1){
        ObjLaser_SetLength(l,length);
         }    
         Speed;
       task Speed{
       let radius = 0;
        while(ObjLaser_GetLength(l) <= length){
           ObjLaser_SetLength(l,ObjLaser_GetLength(l)+v);
           wait(1);
         }
   while(!Obj_BeDeleted(l)){
         Obj_SetX(l,Obj_GetX(l)+v*cos(angle));
          Obj_SetY(l,Obj_GetY(l)+v*sin(angle));
         wait(1);
            }
         /*   while(!Obj_BeDeleted(l)){
               Obj_SetX(l,Obj_GetX(l)+offsetX(radius,angle));
               Obj_SetY(l,Obj_GetY(l)+offsetY(radius,angle));
             radius = v;
             wait(1);
             } */
          }
        Point;
          task Point{
              while(!Obj_BeDeleted(l)){
               if(IsBGStopping){
         let v = 0;  let color = 31; let delay = 10;
           ascent(a in 1..13){
             let x = Obj_GetX(l)+offsetX(10*(a-1),angle);
             let y = Obj_GetY(l)+offsetY(10*(a-1),angle);
           P(x,y,v,angle,color,delay,a);
           }
           Obj_Delete(l);
          }
          wait(1);
           }
         }
        Del;
        task Del{
           while(!Obj_BeDeleted(l)){
        let radius = ((Obj_GetX(l)-GetX)^2+(Obj_GetY(l)-GetY)^2)^0.5;
              if(radius >= 360){
               Obj_Delete(l);
                }
             wait(1);
             }
          }
     }         

 task P2(x,y,v,angle,color,delay,id,xbase,ybase){
        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,true);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
      Obj_SetAutoDelete(p,false);
   wait(delay);
     if(id == 0){
    Obj_SetAutoDelete(p,true);
        Plot;
       task Plot{
        let fam = rand(0,3);
          while(!Obj_BeDeleted(p)){
             if(IsBGStopping){
       if(fam >= 1){
               ObjShot_SetGraphic(p,color-40);
           }
       else if(fam < 1){ObjShot_SetGraphic(p,255);}
              Obj_SetSpeed(p,v/5);
             }
            else{ObjShot_SetGraphic(p,color); Obj_SetSpeed(p,v);}
            wait(1);
            }
         }
       }
     else if(id >=1 && id <= 12){
      Obj_SetAutoDelete(p,false);
        Spin;
        task Spin{
        function set_xy(radius,an){
             Obj_SetAngle(p,Obj_GetAngle(p)+an);   
             Obj_SetX(p,xbase+offsetX(radius,Obj_GetAngle(p)));
             Obj_SetY(p,ybase+offsetY(radius,Obj_GetAngle(p)));
            }
       let n = (22.5+45*2)/290;
         let radius4 = ((Obj_GetX(p)-xbase)^2+(Obj_GetY(p)-ybase)^2)^0.5;
            while(!Obj_BeDeleted(p)){
             if(IsBGStopping){
            set_xy(radius4,(-1)^id*n);
            wait(1);
             }
         else if(!IsBGStopping && id != 1){Obj_Delete(p);}
         else if(!IsBGStopping && id == 1){
         let x2 = Obj_GetX(p);
             let y2 = Obj_GetY(p);
       let v = 2;  let color = 31; let delay = 0;
      let width = 8; let length = 120;
     let angle = Obj_GetAngle(p);
    /*  L2(x2,y2,v,angle,length,width,color,1);
   CreateLaser01(x2,y2,v,angle,length,width,color,delay); */
   LL(x2,y2,v,angle,length,width,15,delay);
           wait(1);
          Obj_Delete(p);
               }
             }
           }
       }
          Del;
        task Del{
           while(!Obj_BeDeleted(p)){ 
          let radius5 = ((Obj_GetX(p)-xbase)^2+(Obj_GetY(p)-ybase)^2)^0.5;
              if(radius5 >= 480){
               Obj_Delete(p);
                }
             wait(1);
             }
          }
     }        

  task L2(x,y,v,angle,length,width,color,delay,id){
              let l = Obj_Create(OBJ_LASER);
              arrayL = arrayL ~ [l];
              Obj_SetX(l,x);
              Obj_SetY(l,y);
              Obj_SetAngle(l,angle);
             ObjShot_SetDelay(l,delay);
              ObjShot_SetGraphic(l,color);
              Obj_SetCollisionToObject(l,true);
              Obj_SetCollisionToPlayer(l,true);
              ObjLaser_SetLength(l,0); 
              ObjLaser_SetWidth(l,width);
              ObjLaser_SetSource(l,false);
         Obj_SetAutoDelete(l,true);
      if(id == 1){
        ObjLaser_SetLength(l,length);
         }    
         Speed;
       task Speed{
        let radius2 = 0;
        while(ObjLaser_GetLength(l) <= length){
           ObjLaser_SetLength(l,ObjLaser_GetLength(l)+v);
           wait(1);
         }
   while(!Obj_BeDeleted(l)){
         Obj_SetX(l,Obj_GetX(l)+v*cos(angle));
          Obj_SetY(l,Obj_GetY(l)+v*sin(angle));
         wait(1);
            }
          /*  while(!Obj_BeDeleted(l)){
               Obj_SetX(l,Obj_GetX(l)+offsetX(radius2,angle));
               Obj_SetY(l,Obj_GetY(l)+offsetY(radius2,angle));
             radius2 = v;
             wait(1);
             }  */
          }
        Point;
          task Point{
              while(!Obj_BeDeleted(l)){
               if(IsBGStopping){
         let v = 0;  let color = 31; let delay = 10;
           ascent(a in 1..13){
             let x2 = Obj_GetX(l)+offsetX(10*(a-1),angle);
             let y2 = Obj_GetY(l)+offsetY(10*(a-1),angle);
           P2(x2,y2,v,angle,color,delay,a,x,y);
           }
           Obj_Delete(l);
          }
          wait(1);
           }
         }
        Del; 
        task Del{
           while(!Obj_BeDeleted(l)){
        let radius3 = ((Obj_GetX(l)-x)^2+(Obj_GetY(l)-x)^2)^0.5;
              if(radius3 >= 480){
               Obj_Delete(l);
                }
             wait(1);
             }
          }
     }  

 task LL(x,y,v,angle,length,width,color,delay){
              let l = Obj_Create(OBJ_LASER);
              arrayL = arrayL ~ [l];
              Obj_SetX(l,x);
              Obj_SetY(l,y);
              Obj_SetSpeed(l,v);
              Obj_SetAngle(l,angle);
              ObjShot_SetGraphic(l,color);
              Obj_SetCollisionToObject(l,true);
              Obj_SetCollisionToPlayer(l,true);
              ObjLaser_SetLength(l,length); 
              ObjLaser_SetWidth(l,width);
              ObjLaser_SetSource(l,false);
         Obj_SetAutoDelete(l,true);
       while(!Obj_BeDeleted(l)){
         Obj_SetX(l,Obj_GetX(l)+v*cos(angle));
          Obj_SetY(l,Obj_GetY(l)+v*sin(angle));
         wait(1);
            }
   }

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