
#Title[冷符 「パゴファジア」（氷食症）]
#Text[チルノ・スペル1]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
   let name        = "冷符 「パゴファジア」";
   let imgBOSS = csd~"img\dot_cirno.png";
   let shotData = csd ~ "data_usershot.txt";
  let effect = csd ~ "img\circle.png";

   @Initialize{
 /* SetCommonDataEx("","bg",1);
     CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(1200000); */
           SetLife(2000);
      SetDamageRate(100,80);
        /*   SetTimer(34); */
           SetInvincibility(360); 
         sgr(0,0);
         SetMovePosition03(GetCenterX,GetClipMinY+60,20,20);
        SetAlpha(255);
           LoadGraphic(imgBOSS);
    LoadGraphic(effect);
          LoadUserShotData(shotData);
           TMain;
    }

   @MainLoop{
    if(OnEvent){break;}
           SetCollisionA(GetX, GetY, 24);
           SetCollisionB(GetX, GetY, 18);

         yield;
       }

   @DrawLoop{
         SetTexture(imgBOSS);  
        DrawGraphic(GetX,GetY);
     }

    @Finalize{
  SetCommonDataEx("","bg",0);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
  loop(48){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,150)); 
       }   
     }
 
     task TMain{
  yield;
 CreateEventFromScript("Talk");
 while(OnEvent){wait(1);}
  SetCommonDataEx("","bg",1);
     CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(1200000);
      SetDamageRate(100,80);
           SetTimer(34);
           SetInvincibility(120); 
  Circle(25);
          wait(90);
     sgr(4,2);
        Shot;
        Count;
        Move;
     loop{
      DeleteEnemyShotImmediatelyInCircle(ALL,GetX,GetY,8);
       wait(1);
       }
    }

   task Shot{
     Shot1;
     Shot2;
    task Shot1{
    let radius = 480;
    let way = 6;
    loop{
      ascent(a in 0..way){
      let base = GetAngleToPlayer+360/way*a;
      let x = GetX+offsetX(radius,base);
      let y = GetY+offsetY(radius,base);
      Ice(x,y,3,base+180,BLUE03,60);
          }
       wait(20);
         }
       }
     task Shot2{
    loop{
      let base = rand(-180,180);
       let radius = rand(500,560);
      let x = GetX+offsetX(radius,base);
      let y = GetY+offsetY(radius,base);
      Ice(x,y,rand(0.5,4),base+180,BLUE23,60);
       wait(1);
         }
       }
    }

 task Ice(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,false);
         ObjShot_SetBombResist(p,false);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
      Angle;
       task Angle{
        while(!Obj_BeDeleted(p)){
        Obj_SetAngle(p,atan2(GetY-Obj_GetY(p),GetX-Obj_GetX(p)));
        wait(1);
          }
        }
    }

    task Move{
   wait(180);
   let f = 60;
   loop{
    let x = GetX + rand(48,64)*(-1)^rand_int(0,99);
    let y = GetY + rand(-32,32);
    if(x < minx+64){x = minx+64;}
    else if(x > maxx-64){x = maxx-64;}
    if(y < miny+16){y = miny+16;}
    else if(y > miny+120){y = miny+120;}
   if(GetX > x){sgr(2,0);}
   else if(GetX < x){sgr(2,2);}
    SetMovePosition02(x,y,f);
     wait(f);
     sgr(4,2);
    wait(120);
        }
    }

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

  function sgr(a,b){SetGraphicRect(a*128,b*128,(a+1)*128,(b+1)*128);}

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

script_event Talk{
    @Initialize{
  }
    @MainLoop{
  if(GetPlayerType == REIMU_A || GetPlayerType == REIMU_B){
       TextOutB(120,"\c[RED]何よ、また来たの？");
       TextOutB(120,"\c[BLUE]あんたに用はないわ");
       TextOutB(120,"\c[RED]むかつく〜\nこの前のリベンジよ！");
       TextOutB(120,"\c[RED]あたいの本気、見せてやる！");
         }
  else if(GetPlayerType == MARISA_A || GetPlayerType == MARISA_B){
       TextOutB(120,"\c[RED]何よ、また来たの？");
       TextOutB(120,"\c[BLUE]お前に用は無いぜ");
       TextOutB(120,"\c[RED]むかつく〜\nこの前のリベンジよ！");
       TextOutB(120,"\c[RED]あたいの本気、見せてやる！");
         }
       End;
      }
   @Finalize{
      }
    }