
#Title[雛スペル2]
#Text[雛スペル2]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
     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-kaze-ti2.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\tm2_shoot003.wav";
   let se2 = csd~ "bgm\tm2_coin000.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");
  if(dif == 2){name        = "厄符　「デフレスパイラル -Lunatic-」";}
   @Initialize{
         CutIn(KOUMA, name, "", 0, 0, 0, 0);
           if(GetPlayerType == REIMU_A){SetLife(1750);}
            else{SetLife(1750);}
           SetTimer(75);
           SetScore(2000000);
           SetDamageRate(35,40);
           SetInvincibility(120);
           SetGraphicRect(128,64,192,128);
           SetMovePosition03(GetCenterX,GetClipMinY+20,20,5);
           MagicCircle(false);	
   /* SetShotColor(64,64,64);*/
           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{
   SetShotColor(255,255,255);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4);
        if(!IsTimeOut){
                loop(64){
              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);
      SetSpeed(0.05);
       SetAngle(90);
        if(dif == 1){Shot;} 
   else if(dif == 2){Shot2;}
     /*   Move;*/
        Count;
    }

      task Shot{
         let radius = 0;
         let v = 2;
         let delay = 60;
         let angle = 120;
        loop{
         ascent(b in 0..60){
            ascent(a in 0..9){
            let x = GetX+offsetX(radius,angle+7*(a-5)+6*b);
            let y = GetY+offsetY(radius,angle+7*(a-5)+6*b);
            let color = rand_int(248,250);   /* rand_int(129,136); */
            CreateShot01(x,y,v,angle+7*(a-5)+6*b,color,delay);
           }
            ascent(a in 0..9){
            let x = GetX+offsetX(radius,180+angle+7*(a-5)+6*b);
            let y = GetY+offsetY(radius,180+angle+7*(a-5)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,180+angle+7*(a-5)+6*b,color,delay);
           }
          ascent(a in 0..9){
            let x = GetX+offsetX(radius,90+angle+13*(a-4)+6*b);
            let y = GetY+offsetY(radius,90+angle+13*(a-4)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,90+angle+13*(a-4)+6*b,color,delay);
           }
           ascent(a in 0..9){
            let x = GetX+offsetX(radius,-90+angle+13*(a-4)+6*b);
            let y = GetY+offsetY(radius,-90+angle+13*(a-4)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,-90+angle+13*(a-4)+6*b,color,delay);
           }
         wait(8);
         }
         descent(b in 0..60){
            ascent(a in 0..9){
            let x = GetX+offsetX(radius,angle+7*(a-5)+6*b);
            let y = GetY+offsetY(radius,angle+7*(a-5)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,angle+7*(a-5)+6*b,color,delay);
           }
            ascent(a in 0..9){
            let x = GetX+offsetX(radius,180+angle+7*(a-5)+6*b);
            let y = GetY+offsetY(radius,180+angle+7*(a-5)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,180+angle+7*(a-5)+6*b,color,delay);
           }
          ascent(a in 0..9){
            let x = GetX+offsetX(radius,90+angle+13*(a-4)+6*b);
            let y = GetY+offsetY(radius,90+angle+13*(a-4)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,90+angle+13*(a-4)+6*b,color,delay);
           }
           ascent(a in 0..9){
            let x = GetX+offsetX(radius,-90+angle+13*(a-4)+6*b);
            let y = GetY+offsetY(radius,-90+angle+13*(a-4)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,-90+angle+13*(a-4)+6*b,color,delay);
           }
         wait(8);
         }
       }
    }

 task Shot2{
    ShotA;
   task ShotA{
         let radius = 0;
         let v = 2.5;
         let delay = 20;
         let angle = 120;
   let n = 0; let m = 0;
        loop{
         ascent(b in 0..60){
            ascent(a in 0..9){
            let x = GetX+offsetX(radius,angle+7*(a-5)+6*b);
            let y = GetY+offsetY(radius,angle+7*(a-5)+6*b);
            let color = rand_int(248,250);   /* rand_int(129,136); */
            CreateShot01(x,y,v,angle+7*(a-5)+6*b,color,delay);
           }
            ascent(a in 0..9){
            let x = GetX+offsetX(radius,180+angle+7*(a-5)+6*b);
            let y = GetY+offsetY(radius,180+angle+7*(a-5)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,180+angle+7*(a-5)+6*b,color,delay);
           }
          ascent(a in 0..9){
            let x = GetX+offsetX(radius,90+angle+13*(a-4)+6*b);
            let y = GetY+offsetY(radius,90+angle+13*(a-4)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,90+angle+13*(a-4)+6*b,color,delay);
           }
           ascent(a in 0..9){
            let x = GetX+offsetX(radius,-90+angle+13*(a-4)+6*b);
            let y = GetY+offsetY(radius,-90+angle+13*(a-4)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,-90+angle+13*(a-4)+6*b,color,delay);
           }
      angle += n*(n+1)/2;
      n += 1;
         wait(7);
         }
         descent(b in 0..60){
            ascent(a in 0..9){
            let x = GetX+offsetX(radius,angle+7*(a-5)+6*b);
            let y = GetY+offsetY(radius,angle+7*(a-5)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,angle+7*(a-5)+6*b,color,delay);
           }
            ascent(a in 0..9){
            let x = GetX+offsetX(radius,180+angle+7*(a-5)+6*b);
            let y = GetY+offsetY(radius,180+angle+7*(a-5)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,180+angle+7*(a-5)+6*b,color,delay);
           }
          ascent(a in 0..9){
            let x = GetX+offsetX(radius,90+angle+13*(a-4)+6*b);
            let y = GetY+offsetY(radius,90+angle+13*(a-4)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,90+angle+13*(a-4)+6*b,color,delay);
           }
           ascent(a in 0..9){
            let x = GetX+offsetX(radius,-90+angle+13*(a-4)+6*b);
            let y = GetY+offsetY(radius,-90+angle+13*(a-4)+6*b);
            let color = rand_int(248,250);
            CreateShot01(x,y,v,-90+angle+13*(a-4)+6*b,color,delay);
           }
     angle = m*(m-1)/2;
   m += 1;
         wait(7);
         }
       }
      }
  ShotB;
   task ShotB{
     let base = 0;
      loop{
       ascent(a in 0..6){
        let angle = base + 60*a;
       CreateShot01(GetX,GetY,1.5,angle,197,20);
       }
     ascent(a in 0..6){
        let angle = -base + 60*a;
       CreateShot01(GetX,GetY,3,angle,198,20);
       }
     base += 4.3;
      wait(6);
       }
      }
    }

     task Move{
       wait(30);
      loop{
        let x = rand(GetClipMinX+92,GetClipMaxX-92);
        let y = rand(GetClipMinY+48,GetClipMinY+120);
         SetMovePosition01(x,y,1);
        wait(120);
         }
    }
       
      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;}
       }
}