script_enemy_main {
  #include_function "lib\Ikareimu\Enemy.dnh"
  
  let count=0;
  let imgEnemy="script\Ikareimu\img\sprite\FairyBlueLarge.png";
  let imgMagicCircle="script\Ikareimu\img\MagicCircleBlue.png";
  let sfxShot="script\Ikareimu\sfx\ZUN\se_tan00.wav";
  let drawCount=0;
  let difficulty = GetCommonData("difficulty");
  
  let laser=0;
  @Initialize {
    IkareimuEnemy_Initialize;
    IkareimuEnemy_SetPolarity(BLUE);
    
    // Set the life to how much health you would like the enemy to have plus 10000.
    // This is a work around for an issue Danmakufu cannot address easily.
    SetLife(10400);
    SetMovePosition03(GetX, GetY+200, 20, 5);
  }
  
  @MainLoop {
  
    // This if statement is the "real" @MainLoop. Sorry, but this is part of the
    // work around mentioned above.
    if(GetLife > 10000){
      IkareimuEnemy_SetCollisionA(GetX, GetY, 24);
      SetCollisionB(GetX, GetY, 12);
      
      if(count%60==59 && GetY>32){
        PlaySE(sfxShot);
        let speed;
        let bulletcount;
        if(difficulty=="easy"){
          speed = 2;
          bulletcount = 3;
        }
        if(difficulty=="normal"){
          speed = 2.5;
          bulletcount = 4;
        }
        if(difficulty=="hard"){
          speed = 3;
          bulletcount = 7;
        }
        if(difficulty=="lunatic"){
          speed = 3.5;
          bulletcount = 8;
        }
        if(difficulty=="fuckingwhat"){
          speed = 4;
          bulletcount = 10;
        }
        let random = rand(0, 360);
        ascent(i in 0..8){
          descent(j in 0..bulletcount){
            let angle = i*45+random;
            ColorShot_Create(BLUE, GetX+cos(angle+130)*j*6, GetY+sin(angle+130)*j*6, speed, angle, BLUE21, 10);
            ColorShot_Create(BLUE, GetX+cos(angle-130)*j*6, GetY+sin(angle-130)*j*6, speed, angle, BLUE21, 10);
            angle = i*45+random+22.5;
            ColorShot_Create(BLUE, GetX+cos(angle+130)*j*6, GetY+sin(angle+130)*j*6, speed*0.75, angle, BLUE21, 10);
            ColorShot_Create(BLUE, GetX+cos(angle-130)*j*6, GetY+sin(angle-130)*j*6, speed*0.75, angle, BLUE21, 10);
          }
        }
      }
      
      if(count>30&&count<210){
        if(difficulty=="hard"||difficulty=="lunatic"||difficulty=="fuckingwhat" && count%5==0){
          PlaySE(sfxShot);
          ColorShot_Create(BLUE, GetX, GetY, rand(2, 4), rand(GetAngleToPlayer-90, GetAngleToPlayer+90), BLUE01, 10);
        }
        if(difficulty=="lunatic"||difficulty=="fuckingwhat" && count%5==0){
          ColorShot_Create(BLUE, GetX, GetY, rand(2.5, 4.5), rand(GetAngleToPlayer-90, GetAngleToPlayer+90), BLUE01, 10);
        }
        if(difficulty=="fuckingwhat" && count%5==0){
          ColorShot_Create(BLUE, GetX, GetY, rand(3, 5), rand(GetAngleToPlayer-90, GetAngleToPlayer+90), BLUE01, 10);
        }
      }
      
      if(count==240){
        SetMovePosition01(GetX, GetClipMinY-50, 3);
      }
      
      if(count>=240 && GetY<GetClipMinY-32){
        IkareimuEnemy_VanishEnemy;
      }
      
      count++;
    }
    // End of "real" @MainLoop
    
    IkareimuEnemy_Run;
    
    if(GetLife <= 10000){
    
      // This if statement is the "real" @Finalize. Yup. Part of the work around.
      if(!FinalizeRun){
        FinalizeRun = true;
        IkareimuEnemy_AddChainCount;
        // Things like visual and sound effects during death must be handled manually here.
      }
      // End of "real" @Finalize.
      
      autoDeathCounter++;
      // Remove the enemy 10 seconds after the enemy "dies".
      // Also removes the enemy if there are no more bullets to detect.
      if(autoDeathCounter == 600 || GetEnemyShotCount<=GetEnemyNum){
        VanishEnemy;
      }
    }
  }
  
  @Finalize {
    IkareimuEnemy_Finalize;
  }
  
  @DrawLoop {
  
    // This if statement is the "real" @DrawLoop.
    if(GetLife > 10000){
      SetTexture(imgMagicCircle);
      SetGraphicRect(0, 0, 77, 77);
      SetGraphicAngle(0, 0, drawCount);
      DrawGraphic(GetX, GetY);
      
      SetTexture(imgEnemy);
      if(drawCount%32>=0 && drawCount%32<8){
        SetGraphicRect(0,0,37,34);
      }
      if((drawCount%32>=8 && drawCount%32<16) || drawCount%32>=24){
        SetGraphicRect(37,0,74,34);
      }
      if(drawCount%32>=16 && drawCount%32<24){
        SetGraphicRect(74,0,111,34);
      }
      SetGraphicAngle(0, 0, 0);
      DrawGraphic(GetX, GetY);
      drawCount++;
    }
    // End of "real" @Drawloop.

  }
}