script_enemy_main {
  #include_function "lib\Ikareimu\Enemy.dnh"
  
  let count=-30;
  let imgEnemy="script\Ikareimu\img\sprite\Cirno.png";
  let sfxShot="script\Ikareimu\sfx\ZUN\se_tan00.wav";
  let sfxLaser="script\Ikareimu\sfx\ZUN\se_lazer00.wav";
  let sfxSpark="script\Ikareimu\sfx\ZUN\se_nep00.wav";
  let difficulty = GetCommonData("difficulty");
  let imagealpha = 255;

  @Initialize {
    IkareimuEnemy_SetPolarity(NONE);
    
    LoadGraphic(imgEnemy);
    
    SetLife(9999);
    SetDamageRate(0, 0);
    CreateEventFromScript("CirnoTalk");
    SetMovePosition03(GetCenterX, GetClipMinY+120, 12, 8);
  }
  
  @MainLoop {
    SetCollisionB(GetX, GetY, 24);
    if(!OnEvent){
      if(count==-30){
        IkareimuEnemy_Initialize;
      }
      if(count%90==0 && count<270 && count>=0){
        TriangleBurst(GetAngleToPlayer, 5);
        SetMovePosition03(GetCenterX+rand(-100, 100), GetClipMinY+rand(90,120), 12, 4);
      }
      
      if(count>=270 && count<630){
        let bulletcount;
        if(difficulty=="easy"){
          bulletcount = 10;
        }
        if(difficulty=="normal"){
          bulletcount = 14;
        }
        if(difficulty=="hard"){
          bulletcount = 27;
        }
        if(difficulty=="lunatic"){
          bulletcount = 20;
        }
        if(difficulty=="fuckingwhat"){
          bulletcount = 30;
        }
        if(count%15==0){
          PlaySE(sfxShot);
          let randomX = GetX+rand(-100, 100);
          let randomY = GetY+rand(-100, 100);
          loop(bulletcount){
            ColorShot_Create(BLUE, randomX, randomY, rand(2, 4), rand(0, 360),  BLUE11, 20);
          }
        }
        if(count%180==90){
          SetMovePosition03(GetCenterX+rand(-150, 150), GetClipMinY+rand(90, 150), 12, 5);
        }
      }
        
      if(count==660){
        SetMovePosition03(GetCenterX, GetClipMinY+100, 12, 5);
      }
      
      if(count>=720&&count<1320){
        let interval;
        if(difficulty=="easy"){
          interval = 3;
        }
        if(difficulty=="normal"){
          interval = 3;
        }
        if(difficulty=="hard"){
          interval = 2;
        }
        if(difficulty=="lunatic"){
          interval = 2;
        }
        if(difficulty=="fuckingwhat"){
          interval = 1;
        }
        if(count%interval==0){
          PlaySE(sfxShot);
          ColorShot_Create(BLUE, GetX, GetY, rand(2, 4), rand(0, 360),  BLUE02, 10);
        }
      }
      
      if(count==1410){
        PlaySE(sfxLaser);
        CreateLaserA(0, GetClipMaxX+50, GetCenterY-20, 500, 200, MASTERSPARK, 66);
        SetLaserDataA(0, 0, 200, 0, 0, 0, 0);
        SetShotKillTime(0, 65);
        FireShot(0);
      }
      
      if(count==1470){
        PlaySE(sfxSpark);
        CreateLaserA(0, GetClipMaxX+50, GetCenterY-20, 500, 200, MASTERSPARK, 1);
        SetLaserDataA(0, 0, 200, 0, 0, 0, 0);
        SetShotKillTime(0, 210);
        FireShot(0);
        CreateLaserA(0, GetClipMaxX+50, GetCenterY+20, 500, 200, MASTERSPARK, 1);
        SetLaserDataA(0, 0, 200, 0, 0, 0, 0);
        SetShotKillTime(0, 210);
        FireShot(0);
        SetMovePosition01(GetClipMinX, GetClipMinY, 0.5);
      }
      
      if(count>1470){
        imagealpha-=5;
        if(imagealpha<0){
          imagealpha=0;
        }
      }
      
      if(count==1530){
        VanishEnemy;
      }
      
      count++;
      yield;
      IkareimuEnemy_Run;
    }
  }
  
  @Finalize {
    IkareimuEnemy_Finalize;
  }
  
  @DrawLoop {
    SetTexture(imgEnemy);
    SetAlpha(imagealpha);
    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);
      }
    }
  }
}




script_event CirnoTalk {

  @Initialize {
  }

  @MainLoop {
    TextOutA("\c[BLUE]I'm not done yet!");
    TextOutA("\c[RED]Sure, sure.\nDo whatever you want.");
    End;
  }

}