
#Title[凍符　「パーフェクトアイスバーン」]
#Text[チルノ・スペル3]
#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 frozen = false;

   @Initialize{
   SetCommonDataEx("","bg",1);
     CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(1500000);
           SetLife(2500);
           SetTimer(42);
      SetDamageRate(100,100);
           SetInvincibility(180);
         sgr(0,0);
         SetMovePosition03(GetCenterX,GetClipMinY+100,20,20);
        SetAlpha(255);
           LoadGraphic(imgBOSS);
          LoadGraphic(effect);
          LoadUserShotData(shotData);
           TMain;
     SetEffectForZeroLife(1,0,0);
    }

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

         yield;
       }

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

    @Finalize{
  SetCommonDataEx("","bg",2);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
 if(!IsTimeOut){
  loop(64){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,150)); 
       } 
     CreateItem(ITEM_1UP,GetX,GetY); 
         } 
     PlaySE(sevanish);
     }
 
     task TMain{
  wait(60);
  loop(3){Explosion01(GetX,GetY,0,10,10);}
     PlaySE(sefreeze);
   Slip;
    wait(60);
      sgr(4,1);
        Shot;
        Count;
    }

     task Shot{
       let delay = 30;
       let color = [RED04,BLUE04,YELLOW04,GREEN04,PURPLE04];
  loop{
 loop(3){
   Move;
   loop(35){
    ascent(a in 0..5){
   let v = rand(1,4);
   let angle = rand(-180,180);
   let x = GetX+offsetX(24,GetAngleToPlayer+72*a);
   let y = GetY+offsetY(24,GetAngleToPlayer+72*a);
     Ice(x,y,v,angle,color[a],delay);
      }
     wait(2);
       }
     }
     wait(90);
     iceburn;
     wait(60);
     Move;
   loop(6){
    ascent(a in 0..6){
      ascent(b in 0..5){
   CreateShot01(GetX,GetY,5-0.5*b,GetAngleToPlayer+20*(a-2)-10,BLUE01,20);
        }
       }
       PlaySE(seshot1);
       wait(10);
       }
     wait(60);
      }
   }

   task Slip{
  let hs = GetPlayerInfo(PLAYER_SPEED_HIGH);
  let ls = GetPlayerInfo(PLAYER_SPEED_LOW);
  let dx = 0; let dy = 0; 
  let f = 10;
  loop{
 let x = GetPlayerX; let y = GetPlayerY;
 if(GetKeyState(VK_LEFT) && !GetKeyState(VK_UP) && !GetKeyState(VK_DOWN) && !GetKeyState(VK_SLOWMOVE)){dx -= hs/f;}
 else if(GetKeyState(VK_LEFT)  && !GetKeyState(VK_UP) && !GetKeyState(VK_DOWN) && GetKeyState(VK_SLOWMOVE)){dx -= ls/f;}
 else if(GetKeyState(VK_RIGHT) && !GetKeyState(VK_UP) && !GetKeyState(VK_DOWN) && !GetKeyState(VK_SLOWMOVE)){dx += hs/f;}
 else if(GetKeyState(VK_RIGHT) && !GetKeyState(VK_UP) && !GetKeyState(VK_DOWN) && GetKeyState(VK_SLOWMOVE)){dx += ls/f;}
 else if(GetKeyState(VK_UP) && !GetKeyState(VK_LEFT) && !GetKeyState(VK_RIGHT) && !GetKeyState(VK_SLOWMOVE)){dy -= hs/f;}
 else if(GetKeyState(VK_UP) && !GetKeyState(VK_LEFT) && !GetKeyState(VK_RIGHT) && GetKeyState(VK_SLOWMOVE)){dy -= ls/f;}
 else if(GetKeyState(VK_DOWN) && !GetKeyState(VK_LEFT) && !GetKeyState(VK_RIGHT) && !GetKeyState(VK_SLOWMOVE)){dy += hs/f}
 else if(GetKeyState(VK_DOWN) && !GetKeyState(VK_LEFT) && !GetKeyState(VK_RIGHT) && GetKeyState(VK_SLOWMOVE)){dy += ls/f;}
 else if(GetKeyState(VK_LEFT) && GetKeyState(VK_UP) && !GetKeyState(VK_SLOWMOVE)){dx -= hs/f/2^0.5; dy -= hs/f/2^0.5;}
 else if(GetKeyState(VK_LEFT)  && GetKeyState(VK_UP) && GetKeyState(VK_SLOWMOVE)){dx -= ls/f/2^0.5; dy -= ls/f/2^0.5;}
 else if(GetKeyState(VK_RIGHT) && GetKeyState(VK_UP) && !GetKeyState(VK_SLOWMOVE)){dx += hs/f/2^0.5; dy -= hs/f/2^0.5;}
 else if(GetKeyState(VK_RIGHT) && GetKeyState(VK_UP) && GetKeyState(VK_SLOWMOVE)){dx += ls/f/2^0.5; dy -= ls/f/2^0.5;}
 else if(GetKeyState(VK_LEFT) && GetKeyState(VK_DOWN) && !GetKeyState(VK_SLOWMOVE)){dx -= hs/f/2^0.5; dy += hs/f/2^0.5;}
 else if(GetKeyState(VK_LEFT)  && GetKeyState(VK_DOWN) && GetKeyState(VK_SLOWMOVE)){dx -= ls/f/2^0.5; dy += ls/f/2^0.5;}
 else if(GetKeyState(VK_RIGHT) && GetKeyState(VK_DOWN) && !GetKeyState(VK_SLOWMOVE)){dx += hs/f/2^0.5; dy += hs/f/2^0.5;}
 else if(GetKeyState(VK_RIGHT) && GetKeyState(VK_DOWN) && GetKeyState(VK_SLOWMOVE)){dx += ls/f/2^0.5; dy += ls/f/2^0.5;}
 else if(OnPlayerMissed){dx = 0; dy = 0;}
 else{dx = dx*0.99; dy = dy*0.99;}
   SetPlayerX(x+dx); SetPlayerY(y+dy);
   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,true);
         ObjShot_SetBombResist(p,false);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
     while(!frozen){wait(1);}
       Obj_SetSpeed(p,0);
       ObjShot_SetGraphic(p,WHITE04); 
       while(frozen){wait(1);}
       Obj_SetAngle(p,rand(-180,180));
      ascent(a in 0..180){
         Obj_SetSpeed(p,a*3/180);
         wait(1);
         }
   }

    task Move{
   let f = 2;
  let r = 0;
 if(GetX > GetPlayerX){r = 1;}
    let x = GetX + rand(64,128)*(-1)^r;
    let y = GetY + rand(-48,48);
    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);}
    SetMovePosition03(x,y,15,f);
     wait(60);
     sgr(4,1);
    }
  
    task iceburn{
        frozen = true;
    Explosion01(GetX,GetY,0.01,2,60);
     PlaySE(sefreeze);
        wait(180);
        frozen = false;
     }

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