
#Title[フランスペル3]
#Text[フランスペル3]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\function_effect.txt"
    #include_script".\function_bullet.txt"
     let name        = "魔剣　「ダーインスレイヴ」";
     let csd = GetCurrentScriptDirectory;
        let gx = GetX;
        let gy = GetY;
        let gspeed = GetSpeed;
        let gangle = GetAngle;     
        let arg = GetArgument;
   let imgBOSS = csd~"img\character\dot_flandre.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\arrow01.wav";
   let se2 = csd~ "bgm\eco02_a.wav";
   let se3 = csd~ "bgm\buble03.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   = "魔剣　「ダーインスレイヴ -Linatic-」";}
   @Initialize{
       /*    CutIn(KOUMA, name, "", 0, 0, 0, 0);   */
           if(GetPlayerType == REIMU_A){SetLife(800);}
            else{SetLife(800);}
    /*       SetTimer(90);
      SetScore(4000000);    */
       SetDamageRate(20,5);
           SetInvincibility(240);
      /*     SetGraphicRect(0*128,0,1*128,128);   
           SetMovePosition03(GetCenterX,GetClipMinY+60,20,5);  */
       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(80){
              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);
  CutIn(KOUMA, name, "", 0, 0, 0, 0);
   SetTimer(90);
     SetScore(4000000);
   PlaySE("seUseSpellCard.wav");
    SetGraphicRect(0*128,0,1*128,128);   
   SetMovePosition03(GetCenterX,GetClipMinY+60,20,5);
 wait(120);
     PlaySE(se2);
    Spark(120,255,0,0,true);
       wait(90);
        if(dif == 1){Sword;}
   else if(dif == 2){Sword2;}
      /*  Move;  */
        Count;
    }

     task Sword{
          let x = GetX;
          let y = GetY;
          let angle = 90;
          let length = 500;
          let width = 25;
          let color = 79;
       loop{
          L(0,x,y,angle,length,width,color);
          wait(300);
          L(1,x,y,angle,length,width,color);
          wait(300);
          L(2,x,y,angle,length,width,color);
          wait(240);
          L(4,x,y,angle+90,length,width,color);
         wait(300);
          L(6,x,y,angle-180,length,width,color);
          wait(240);
          L(8,x,y,angle-90,length,width,color);
          wait(300);
         L(3,x,y,angle,length,width,color);
         wait(300);
           }
         }

 task Sword2{
          let x = GetX;
          let y = GetY;
          let angle = 90;
          let length = 500;
          let width = 25;
          let color = 79;
       loop{
          L(0,x,y,angle-10,length,width,color);
          L(1,x,y,angle+10,length,width,color);
          wait(300);
          L(3,x,y,angle+90,length,width,color);
          wait(300);
          L(5,x,y,angle,length,width,color);
         wait(300);
          L(7,x,y,angle-180,length,width,color);
          wait(300);
          L(8,x,y,angle+90,length,width,color);
          wait(360);
         PlaySE(se2);
    Spark(120,255,0,0,true);
        wait(120);
           }
         }

     task L(id,x,y,angle,length,width,color){
              let l = Obj_Create(OBJ_LASER);
              arrayL = arrayL ~ [l];
              Obj_SetX(l,x);
              Obj_SetY(l,y);
              Obj_SetAngle(l,angle);
              Obj_SetAutoDelete(l,false);
              ObjShot_SetGraphic(l,color);
              Obj_SetCollisionToObject(l,true);
              Obj_SetCollisionToPlayer(l,true);
              ObjLaser_SetLength(l,length);
              ObjLaser_SetWidth(l,width);
              ObjLaser_SetSource(l,true);
              Obj_SetCollisionToPlayer(l,true);
             Set;
            task Set{
              loop{
              Obj_SetX(l,GetX);
              Obj_SetY(l,GetY);
              wait(1);  
             }
           }
            Shot;
            task Shot{
                  let v = 0;
                  let color = 87;
                   let span = 40;
                  let accel = 0.01;
                  let vmax = 1;
                 let delay = 10;
     if(dif == 2){span = 30; v = 0;}
                 while(!Obj_BeDeleted(l)){
                  let angle = Obj_GetAngle(l)-90*(-1)^id;
                 ascent(i in 0..500/span){
                  let x = GetX+offsetX(i*span,Obj_GetAngle(l));
                  let y = GetY+offsetY(i*span,Obj_GetAngle(l));
                  CreateShot02(x,y,v,angle,accel,vmax,color,delay);
                   }
                 PlaySE(se1);
                 vmax += 0.05;
                  if(dif == 1){wait(5);}
            else if(dif == 2){wait(3);}
                  } 
                 }
             if(dif == 1){Angle;}
          else if(dif == 2){Angle2;}
         task Angle{
              wait(10);
           if(id == 0){
               loop(120){
            SetGraphicRect(4*128,2*128,5*128,3*128);
                Obj_SetAngle(l,Obj_GetAngle(l)-3);
                 wait(1);
                }
            SetGraphicRect(2*128,2*128,3*128,3*128);
            move(GetClipMaxX-100,GetClipMinY+64,20,5);
                }
            else if(id == 1){
          SetGraphicRect(2*128,1*128,3*128,2*128);
            move(GetPlayerX,GetY+92,15,3);
               loop(120){
                Obj_SetAngle(l,Obj_GetAngle(l)-3);
                 wait(1);
                }
            move(GetClipMinX+16,GetClipMinY+16,20,5);
                }
            else if(id == 2){
          SetGraphicRect(2*128,2*128,3*128,3*128);
            move(GetClipMaxX-64,GetY+64,15,5);
                wait(80);
           move(GetClipMaxX-16,GetClipMinY+16,15,5);
                }
            else if(id == 4){
          SetGraphicRect(1*128,1*128,2*128,2*128);
            move(GetX-64,GetClipMaxY-64,15,5);
                wait(90);
           move(GetClipMaxX-16,GetClipMaxY-16,15,5);
                }
            else if(id == 6){
           SetGraphicRect(2*128,1*128,3*128,2*128);
            move(GetClipMinX+64,GetY-128,15,5);
                wait(80);
           move(GetClipMinX+16,GetClipMaxY-16,15,5);
                }
          else if(id == 8){
         SetGraphicRect(3*128,2*128,4*128,3*128);
           move(GetX+128,GetClipMinY+64,15,5);
                wait(90);
           move(GetClipMinX+64,GetClipMinY+16,15,5);
                }
            else if(id == 3){
         SetGraphicRect(2*128,2*128,3*128,3*128);
            move(GetPlayerX,GetY+92,15,3);
               loop(120){
                Obj_SetAngle(l,Obj_GetAngle(l)+3);
                 wait(1);
                }
            SetGraphicRect(0*128,0*128,1*128,1*128);
             move(GetCenterX,GetClipMinY+60,20,5);
              }
             Obj_Delete(l);
                }

        task Angle2{
              wait(10);
           if(id == 0){
               loop(116){
            SetGraphicRect(4*128,2*128,5*128,3*128);
                Obj_SetAngle(l,Obj_GetAngle(l)-3);
                 wait(1);
                }
            SetGraphicRect(2*128,2*128,3*128,3*128);
            move(GetClipMaxX-16,GetClipMinY+16,20,5);
                }
            else if(id == 1){
               loop(116){
                Obj_SetAngle(l,Obj_GetAngle(l)+3);
                 wait(1);
                }
                }
            else if(id == 3){
          SetGraphicRect(2*128,2*128,3*128,3*128);
            move(GetClipMinX+48,GetY,15,5);
                loop(90){
                Obj_SetAngle(l,Obj_GetAngle(l)+3);
                 wait(1);
                }
           move(GetClipMinX+16,GetClipMinY+16,15,5);
                }
            else if(id == 5){
          SetGraphicRect(1*128,1*128,2*128,2*128);
            move(GetX,GetClipMaxY-48,15,5);
                 loop(90){
                Obj_SetAngle(l,Obj_GetAngle(l)+3);
                 wait(1);
                }
           move(GetClipMaxX-16,GetClipMaxY-16,15,5);
                }
            else if(id == 7){
           SetGraphicRect(2*128,1*128,3*128,2*128);
            move(GetX,GetClipMinY+48,15,5);
                 loop(90){
                Obj_SetAngle(l,Obj_GetAngle(l)+3);
                 wait(1);
                }
           move(GetClipMaxX-16,GetClipMinY+16,15,5);
                }
          else if(id == 8){
         SetGraphicRect(3*128,2*128,4*128,3*128);
           move(GetClipMinX+48,GetY,15,5);
                loop(90){
                Obj_SetAngle(l,Obj_GetAngle(l)-1);
                 wait(1);
                }
           move(GetCenterX,GetClipMinY+60,15,5);
                }
             Obj_Delete(l);
                }
     }


     task Move{
       wait(30);
      loop{
        let x = rand(-64,64);
        let y = rand(-32,32);
        let v = 2;
        let xmin = GetPlayerX-100;
        let ymin = GetClipMinY+60;
        let xmax = GetPlayerX+100;
        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(3*128,0,4*128,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 offsetX(radius,angle){
           return radius * cos(angle);
     }

        function offsetY(radius,angle){
            return radius * sin(angle);
     }           

       function move(x,y,w,v){
          SetMovePosition03(x,y,w,v);
     }
            
        function sc(r,g,b){
             SetShotColor(r,g,b);
     }

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

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