
#Title[大妖精通常弾幕1]
#Text[大妖精通常弾幕1]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
     let csd = GetCurrentScriptDirectory;
        let gx = GetX;
        let gy = GetY;
        let gspeed = GetSpeed;
        let gangle = GetAngle;     
        let arg = GetArgument;
   let imgBOSS = csd~"img\character\dot_daiyousei.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\arrow01.wav";
   let se2 = csd~ "bgm\eco00.wav";
   let se3 = csd~ "bgm\concentration.wav";
   let se4 = csd~ "bgm\countdown.wav";
    let effect = csd ~ "img\magic_circle\powercircle.png";
   let arrayL = [];
 let dif = GetCommonData("Dif");
   @Initialize{
           if(GetPlayerType == REIMU_A){SetLife(2000);}
            else{SetLife(2000);}
           SetTimer(45);
       SetDamageRate(100,50);
           SetInvincibility(120);
           SetGraphicRect(0*128,0*128,1*128,1*128);   
           SetMovePosition03(GetCenterX,GetClipMinY+100,20,5);
        SetAlpha(255);
           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{
   SetCommonData("TimeOut",IsTimeOut);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4); 
         if(!IsTimeOut){
                loop(30){
              CreateItem(ITEM_SCORE,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
              }
      /*    CreateItem(ITEM_BOMB,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));  */
           }           
     }
 
     task TMain{
          yield;
     Concentration01(90);
     PlaySE(se2);
       wait(90);
      L(GetClipMinX-20,GetClipMinY-20,0,600,1,WHITE01);
      L(GetClipMaxX+20,GetClipMinY-20,90,600,1,WHITE01);
      L(GetClipMinX-20,GetClipMaxY+20,-90,600,1,WHITE01);
        Shot;
        Count;
    }

      task Shot{
     if(dif == 1){Shot1;}
    else if(dif == 2){Shot2;}
     task Shot1{
       let radius = 0;
      let c = [169,171,172,174,175];
      let vir = [1,2,3,4,5];
      let delay = 0;
      let accel = 0;
       loop{
     loop(6){
       ascent(b in 0..5){
         ascent(a in 0..5){
          let angle = GetAngleToPlayer+72*a;
          let v = vir[b];
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
          let color = c[a];
    if(b == 2 && dif == 1){Knife(x,y,v,angle,color,delay);}
    else if(b != 2 && dif == 1){
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,accel,v,color);
         FireShot(0);  
         PlaySE(se1);
            }
          }
        }
      wait(30);
        }  
       move;
        }
       }
  task Shot2{
       let radius = 0;
      let c = [169,171,172,174,175];
      let vir = [1,2,3,4,5];
      let delay = 0;
      let accel = 0;
       loop{
     loop(6){
       ascent(b in 0..5){
         ascent(a in 0..7){
          let angle = GetAngleToPlayer+360/7*a;
          let v = vir[b];
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
          let color = 169+a;
   Knife(x,y,v,angle,color,delay);
          }
        }
   PlaySE(se1);
      wait(30);
        }  
       move;
        }
       }
    }

     function move{
        let x = rand(32,64);
        let y = rand(-32,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(60);
         SetGraphicRect(0*128,0*128,1*128,1*128);   
    }
       
      task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }
     
   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,true);
              ObjLaser_SetLength(l,length);
              ObjLaser_SetWidth(l,width);
              ObjLaser_SetSource(l,true);
              Obj_SetCollisionToPlayer(l,true);
     }

     task Knife(x,y,v,angle,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);

         while(!Obj_BeDeleted(p)){
           let i = 0;    /* arrayL[i]*/
             loop(length(arrayL)){
             if(Collision_Obj_Obj(p,arrayL[i])){
         CreateShot01(Obj_GetX(p),Obj_GetY(p),Obj_GetSpeed(p),Obj_GetAngle(arrayL[i])+90,color,delay);  
             Obj_Delete(p); 
        wait(1);  
             break;
             }
         i++;
         if(i == 4){i = 0;}
         }
        wait(1);
        }
    }


    function offsetX(radius,angle){
           return radius * cos(angle);
     }

        function offsetY(radius,angle){
            return radius * sin(angle);
     }           
            
        function sc(r,g,b){
             SetShotColor(r,g,b);
     }

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

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