
#Title[氷符 「ブルークリスタル」]
#Text[チルノ・スペル2]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
  let name        = "氷符 「ブルークリスタル」";
    #include_script".\Local.txt"
   let imgBOSS = csd~"img\dot_cirno.png";
   let shotData = csd ~ "data_usershot.txt";
   let effect = csd ~ "img\circle.png";
   let arrayL = [];

   @Initialize{
   SetCommonDataEx("","bg",1);
     CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(1500000);
           SetLife(2500);
      SetDamageRate(100,80);
           SetTimer(51);
           SetInvincibility(120);
         sgr(0,0);
         SetMovePosition03(GetCenterX,GetClipMinY+60,20,20);
        SetAlpha(255);
           LoadGraphic(imgBOSS);
          LoadGraphic(effect);
          LoadUserShotData(shotData);
   Circle(25);
           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{
          wait(90);
        Shot;
        Count;
   /*  DamageBoss(100); */
    }

     task Shot{
   let color = BLUE03;
    let delay = 20;
    let v = 5.7;
   loop{
   sgr(4,2);
    let x = GetX; let y = GetY;
    let angle = GetAngleToPlayer;
    Ice(x,y,v,angle,color,delay);
     wait(30);
    sgr(0,0);
  loop(3){
      wait(190);
     Move;
    }
      wait(60);
      }
   }

   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,true);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
    wait(delay);
        while(!Obj_BeDeleted(p) && Obj_GetSpeed(p) > 0){
        Obj_SetSpeed(p,Obj_GetSpeed(p)-0.1);
        wait(1);
         }
       Obj_SetSpeed(p,0);
      wait(45);
    let x = Obj_GetX(p);
    let y = Obj_GetY(p);
  if(!Obj_BeDeleted(p)){Explosion01(x,y,0,0.5,180);
       PlaySE(sefreeze);}
    let width = 30;
    let color = 86;
    let length = 130;
    let dlength = length/10;
     let kill = 360;
   let way = 6;
  let base = Obj_GetAngle(p);
  if(!Obj_BeDeleted(p)){
    ascent(a in 0..6){
      let angle = base+60*a;
      CreateLaserA(0,x,y,0,width,color,0);
      SetLaserDataA(0,0,angle,0,dlength,0,0);
      SetLaserDataA(0,10,NULL,0,0,0,0);
      SetShotKillTime(0,kill);
      FireShot(0);
       }
   wait(10);
     ascent(a in 0..6){
      let angle = base+60*a+120;
    let dx = offsetX(length,angle-120);
    let dy = offsetY(length,angle-120);
      CreateLaserA(0,x+dx,y+dy,0,width,color,0);
      SetLaserDataA(0,0,angle,0,dlength,0,0);
      SetLaserDataA(0,10,NULL,0,0,0,0);
      SetShotKillTime(0,kill-10);
      FireShot(0);
       }
    wait(10);
    ascent(a in 0..6){
      ascent(b in 0..3){
      let angle = base+60*a;
    let dx = offsetX(length,angle);
    let dy = offsetY(length,angle);
      CreateLaserA(0,x+dx,y+dy,0,width,color,0);
      SetLaserDataA(0,0,angle+60*(b-1),0,dlength/3,0,0);
      SetLaserDataA(0,20,NULL,0,0,0,0);
      SetShotKillTime(0,kill-20);
      FireShot(0);
         }
       }
  wait(20);
   ascent(a in 0..6){
      ascent(b in 0..3){
        ascent(c in 0..6){
      let angle = base+60*a;
    let dx = offsetX(length,angle);
    let dy = offsetY(length,angle);
    let ddx = offsetX(length*2/3,angle+60*(b-1));
    let ddy = offsetY(length*2/3,angle+60*(b-1));
      CreateLaserA(0,x+dx+ddx,y+dy+ddy,0,width,color,0);
      SetLaserDataA(0,0,angle+60*(b-1)+60*(c-1),0,dlength/10,0,0);
      SetLaserDataA(0,120,NULL,0,0,0,0);
      SetShotKillTime(0,kill-40);
      FireShot(0);
       }
      }
     }
   }
    if(!Obj_BeDeleted(p)){
    wait(kill-60);
  let color = 48;
  let delay = 0;
   ascent(a in 0..way){
   let angle = atan2(GetPlayerY-y,GetPlayerX-x)+360/way*a;
    CreateShot02(x,y,0,angle,0.01,0.5,color,delay);
     }
   ascent(b in 0..6){
   ascent(a in 0..way){
   let angle = atan2(GetPlayerY-y,GetPlayerX-x)+360/way*a;
   let dx = offsetX(length,base+60*b);
   let dy = offsetY(length,base+60*b);
    CreateShot02(x+dx,y+dy,0,angle,0.01,0.5,color,delay);
     }
     }
  ascent(c in 0..3){
   ascent(b in 0..6){
   ascent(a in 0..way){
   let angle = atan2(GetPlayerY-y,GetPlayerX-x)+360/way*a;
   let dx = offsetX(length,base+60*b);
   let dy = offsetY(length,base+60*b);
   let ddx = offsetX(length*2/3,base+60*b+60*(c-1));
   let ddy = offsetY(length*2/3,base+60*b+60*(c-1));
    CreateShot02(x+dx+ddx,y+dy+ddy,0,angle,0.01,0.5,color,delay);
     }
     }
     }
   }
       Obj_Delete(p);
    }

    task Move{
   let f = 30;
   let x = GetX + 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,1);}
   else if(GetX < x){sgr(2,3);}
    SetMovePosition02(x,y,f);
     wait(f);
     sgr(0,0);
    }

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