script_enemy_main {
  #include_function "lib\Ikareimu\Enemy.dnh"
  
  let frame=-60;
  let imgBoss="script\Ikareimu\img\sprite\Cirno.png";
  let sfxShot="script\Ikareimu\sfx\ZUN\se_tan00.wav";
  let difficulty = GetCommonDataDefault("difficulty", "fuckingwhat");
  
  @Initialize {
    IkareimuEnemy_Initialize;
    IkareimuEnemy_SetPolarity(BLUE);
    
    LoadGraphic(imgBoss);
    
    SetLife(3000);
    SetTimer(50);
    SetInvincibility(60);
    SetEnemyMarker(true);
    
    SetMovePosition03(GetCenterX, GetClipMinY+120, 12, 8);
  }
  
  @MainLoop {
    IkareimuEnemy_SetCollisionA(GetX, GetY, 48);
    SetCollisionB(GetX, GetY, 24);
    
    if(frame==20 && frame>=0){
      SetMovePosition03(GetCenterX+rand(40, 100), GetClipMinY+rand(90,120), 12, 4);
      TriangleBurst(GetAngleToPlayer, 3);
    }
    if(frame==30 && frame>=0){
      TriangleBurst(GetAngleToPlayer, 5);
    }
    if(frame==40 && frame>=0){
      TriangleBurst(GetAngleToPlayer, 7);
    }
    
    if(frame==70 && frame>=0){
      SetMovePosition03(GetCenterX+rand(-100, -40), GetClipMinY+rand(90,120), 12, 4);
      TriangleBurst(GetAngleToPlayer, 3);
    }
    if(frame==80 && frame>=0){
      TriangleBurst(GetAngleToPlayer, 5);
    }
    if(frame==90 && frame>=0){
      TriangleBurst(GetAngleToPlayer, 7);
    }
    
    if(frame==150){
      SetMovePosition03(GetCenterX, GetClipMinY+rand(90,120), 12, 4);
      CircleShots;
    }
    
    if(frame==390){
      frame=0;
    }
    
    yield;
    IkareimuEnemy_Run;
    frame++;
  }
  
  @Finalize {
    IkareimuEnemy_Finalize;
  }
  
  @DrawLoop {
    SetTexture(imgBoss);
    SetGraphicRect(0, 0, 64, 64);
    DrawGraphic(GetX, GetY);
  }
  
  function TriangleBurst(angle, spacing){
    PlaySE(sfxShot);
    let rows;
    if(difficulty == "easy"){
      rows = 5;
    }
    if(difficulty == "normal"){
      rows = 7;
    }
    if(difficulty == "hard"){
      rows = 9;
    }
    if(difficulty == "lunatic"){
      rows = 11;
    }
    if(difficulty == "fuckingwhat"){
      rows = 13;
    }
    ascent(i in 2..2+rows){
      ascent (j in 0..i){
        ColorShot_Create(BLUE, GetX, GetY, 4*(1.1-i*0.05), angle-(i-1)*(spacing/2)+j*spacing,  BLUE23, 10);
      }
    }
  }
  
  task CircleShots{
    let bulletcount;
    let speed;
    let looptime;
    let waittime;
    if(difficulty == "easy"){
      bulletcount = 20;
      speed = 2;
      looptime = 8;
      waittime = 30;
    }
    if(difficulty == "normal"){
      bulletcount = 30;
      speed = 2;
      looptime = 10;
      waittime = 24;
    }
    if(difficulty == "hard"){
      bulletcount = 40;
      speed = 2.5;
      looptime = 12;
      waittime = 20;
    }
    if(difficulty == "lunatic"){
      bulletcount = 50;
      speed = 2.5;
      looptime = 15;
      waittime = 16;
    }
    if(difficulty == "fuckingwhat"){
      bulletcount = 60;
      speed = 3;
      looptime = 24;
      waittime = 10;
    }
    loop(looptime){
      PlaySE(sfxShot);
      let randomangle = rand(0, 360);
      ascent(i in 0..bulletcount){
        ColorShot_Create(BLUE, GetX, GetY, speed, randomangle+i*(360/bulletcount),  BLUE04, 10);
      }
      loop(waittime){yield;}
    }
  }
}