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

script_enemy_main{
    #include_script".\function_effect.txt"
    #include_script".\function_bullet.txt"
     let name        = "Q.E.D　「ブラッディリング in 495」";
     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\tm2_swing001.wav";
   let se2 = csd~ "bgm\eco02_a.wav";
   let se3 = csd~ "bgm\bell01.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   = "Q.E.D　「幻想血華狂　-495年の波紋-」";}
   @Initialize{
    /*    CutIn(KOUMA, name, "", 0, 0, 0, 0);  */
           if(GetPlayerType == REIMU_A){SetLife(1);}
            else{SetLife(1);}
         SetDurableSpellCard;
    /*    SetAlpha(128);
           SetTimer(62);
      SetScore(10000000);   */
       SetDamageRate(0,0);
        if(GetPlayerType == MARISA_B){
           SetDamageRate(0,0);
         }
           SetInvincibility(3600);
           SetGraphicRect(3*128,0,4*128,128);   
     /*      SetMovePosition03(GetCenterX,GetCenterY-0,20,5); */
       MagicCircle(false);
           LoadGraphic(imgBOSS);
          LoadGraphic(effect);
          LoadUserShotData(shotData);
         LoadSE(se1);LoadSE(se2);LoadSE(se3);LoadSE(se4);
     SetEffectForZeroLife(60,64,1);
   SetTexture(imgBOSS);
           TMain;
    }

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

         yield;
       }

   @DrawLoop{  
        DrawGraphic(GetX,GetY);
     if(dif == 2){
       DrawGraphic(2*GetCenterX-GetX,GetY);
      DrawGraphic(2*GetCenterX-GetX,2*GetCenterY-GetY);
     DrawGraphic(GetX,2*GetCenterY-GetY);
        }
     }

    @Finalize{ 
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4);   
              loop(200){
              CreateItem(ITEM_SCORE,GetX+2*offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
              }
       if(GetMissCountInThisSpell == 0){
       loop(3){
              CreateItem(ITEM_BOMB,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
              }
         }  
      else if(GetMissCountInThisSpell != 0){
        CreateItem(ITEM_1UP,GetX,GetY);  
         } 
     }
 
     task TMain{
          yield;
      L(GetClipMinX,GetClipMinY,0,600,1,WHITE01);
      L(GetClipMinX,GetClipMaxY,0,600,1,WHITE01);
      L(GetClipMaxX,GetClipMinY,90,600,1,WHITE01);
      L(GetClipMinX,GetClipMinY,90,600,1,WHITE01);
    wait(120);
   CutIn(KOUMA, name, "", 0, 0, 0, 0);
   PlaySE("seUseSpellCard.wav");
   SetAlpha(128);
           SetTimer(64);
      SetScore(10000000); 
 SetMovePosition03(GetCenterX,GetCenterY,20,5);
 wait(120);
     PlaySE(se2);
    Spark(120,255,0,0,true);
      Circle(40);
        wait(90);
     SetGraphicRect(4*128,2*128,5*128,3*128);
        if(dif == 1){Shot;}
      else if(dif == 2){Shot2;}
        Count;
        Color;
    }

     task Color{
         loop{
           let r = rand(0,255); let g = rand(0,255); let b = rand(0,255);
            SetColor(r,g,b);
             wait(1);
             }
         }

      task Shot{
       let delay = 10;
    let v = 0;
       let vv = [1,1.5,1,0.5,1.5,1,1.5,1.5,1.5,2];
      let accel = 0.01;
      let n = 180;
      let bend = 5;
      let way = 72;
      loop{ 
    ascent(b in 0..1){
      let vmax = vv[b];
      let radius = -32+16*b;
          ascent(a in 0..way){
          let angle = GetAngleToPlayer+360/way*a;
          let color = 81;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
          P(x,y,v,angle,accel,vmax,color,delay);
          }
          } 
     PlaySE(se3);
       if(GetTimer >= 58){n = 180; /*bend = 5; way = 10;*/}
       else if(GetTimer >= 45){n = 150;/* bend = 5; way = 15;*/}
       else if(GetTimer >= 30){n = 120; /*bend = 5; way = 18;*/}
       else if(GetTimer >= 12){n = 90;/* bend = 5; way = 20;*/}
       else if(GetTimer >= 5){n = 60;/* bend = 5; way = 24;*/}
      /*  else if(GetTimer >= 0){n = 30; bend = 5; way = 36;} */
        wait(n);
     let xx = GetPlayerX; let yy = GetPlayerY;
    if(xx < GetClipMinX+50){xx = GetClipMinX+50;}
    if(xx > GetClipMaxX-50){xx = GetClipMaxX-50;}
    if(yy < GetClipMinY+50){yy = GetClipMinY+50;}
    if(yy > GetClipMaxY-50){yy = GetClipMaxY-50;}
      SetMovePosition02(xx,yy,n);
         wait(n);
          }
    }

  task Shot2{
       let delay = 10;
    let v = 0;
       let vv = [1,1.5,1,0.5,1.5,1,1.5,1.5,1.5,2];
      let accel = 0.01;
      let n = 180;
      let bend = 5;
      let way = 36;
    let cx = GetCenterX;
      let cy = GetCenterY;
      loop{ 
    ascent(b in 0..1){
      let vmax = vv[b];
      let radius = -32+16*b;
          ascent(a in 0..way){
          let angle = GetAngleToPlayer+360/way*a;
          let color = 81;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
          P(x,y,v,angle,accel,vmax,color,delay);
           P(2*cx-x,y,v,angle,accel,vmax,color,delay);
          P(x,2*cy-y,v,angle,accel,vmax,color,delay);
         P(2*cx-x,2*cy-y,v,angle,accel,vmax,color,delay);
          }
          } 
     PlaySE(se3);
       if(GetTimer >= 58){n = 180; /*bend = 5; way = 10;*/}
       else if(GetTimer >= 45){n = 150;/* bend = 5; way = 15;*/}
       else if(GetTimer >= 30){n = 120; /*bend = 5; way = 18;*/}
       else if(GetTimer >= 12){n = 90;/* bend = 5; way = 20;*/}
       else if(GetTimer >= 5){n = 60;/* bend = 5; way = 24;*/}
     /*   else if(GetTimer >= 0){n = 30; bend = 5; way = 36;}*/
        wait(n);
     let xx = GetPlayerX; let yy = GetPlayerY;
    if(xx < GetClipMinX+50){xx = GetClipMinX+50;}
    if(xx > GetClipMaxX-50){xx = GetClipMaxX-50;}
    if(yy < GetClipMinY+50){yy = GetClipMinY+50;}
    if(yy > GetClipMaxY-50){yy = GetClipMaxY-50;}
      SetMovePosition02(xx,yy,n);
         wait(n);
          }
    }

    task P(x,y,v,angle,accel,vmax,color,delay){
        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);
     Accel;
      task Accel{
         wait(delay);
           while(!Obj_BeDeleted(p) && Obj_GetSpeed(p)<=vmax){
           Obj_SetSpeed(p,Obj_GetSpeed(p)+accel);
           wait(1);
           }
        }
        while(!Obj_BeDeleted(p)){
           let i = 0;
             loop(length(arrayL)){
             if(Collision_Obj_Obj(p,arrayL[i])){
        CreateShot02(Obj_GetX(p),Obj_GetY(p),Obj_GetSpeed(p),2*Obj_GetAngle(arrayL[i])-Obj_GetAngle(p),accel,vmax,color,0);    
             Obj_Delete(p); 
        wait(1);  
             break;
             }
         i++;
         if(i == 4){i = 0;}
         }
        wait(1);
        }
    }

    task L(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,false);
              ObjLaser_SetLength(l,length);
              ObjLaser_SetWidth(l,width);
              ObjLaser_SetSource(l,false);
     }

     task Move{
       wait(30);
      loop{
        let x = rand(-64,64);
        let y = rand(-32,32);
        let v = 2;
        let xmin = GetClipMinX+100;
        let ymin = GetClipMinY+60;
        let xmax = GetClipMaxX-100;
        let ymax = GetCenterY-120;
        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(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;}
       }
}