script_enemy_main {
  #include_function "lib\Ikareimu\Enemy.dnh"
  
  let count=0;
  let imgEnemy="script\Ikareimu\img\sprite\FairyRedLarge.png";
  let sfxShot="script\Ikareimu\sfx\ZUN\se_tan00.wav";
  let sfxLaser="script\Ikareimu\sfx\ZUN\se_lazer00.wav";
  let drawCount=0;
  let difficulty = GetCommonData("difficulty");
  
  let lasers = [];
  @Initialize {
    IkareimuEnemy_Initialize;
    IkareimuEnemy_SetPolarity(RED);
    
    // 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(10250);
    SetMovePosition03(GetX, GetY+230, 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){
        PlaySE(sfxShot);
        let angle = GetAngleToPlayer;
        let bulletcount;
        let speed;
        if(difficulty=="easy"){
          bulletcount = 20;
          speed = 2;
        }
        if(difficulty=="normal"){
          bulletcount = 30;
          speed = 2;
        }
        if(difficulty=="hard"){
          bulletcount = 40;
          speed = 3;
        }
        if(difficulty=="lunatic"){
          bulletcount = 40;
          speed = 3;
        }
        if(difficulty=="fuckingwhat"){
          bulletcount = 50;
          speed = 4;
        }
        ascent(i in 0..bulletcount){
          ColorShot_Create(RED, GetX, GetY, speed, angle+i*(360/bulletcount), RED04, 10);
          if(difficulty=="hard" || difficulty=="lunatic" || difficulty=="fuckingwhat"){
            ColorShot_Create(RED, GetX, GetY, speed-1, angle+i*(360/bulletcount)+180/bulletcount, RED04, 10);
          }
        }
      }
      
      if(count==120){
        PlaySE(sfxLaser);
        if(difficulty=="easy" || difficulty=="normal"){
          lasers = lasers ~ [ColorLaser_Create(RED, 2, GetX, GetY, 0, GetAngleToPlayer, 500, 20, RED60, 60)];
        }
        if(difficulty=="hard" || difficulty=="lunatic"){
          lasers = lasers ~ [ColorLaser_Create(RED, 2, GetX, GetY, 0, GetAngleToPlayer-10, 500, 20, RED60, 60)];
          lasers = lasers ~ [ColorLaser_Create(RED, 2, GetX, GetY, 0, GetAngleToPlayer, 500, 20, RED60, 60)];
          lasers = lasers ~ [ColorLaser_Create(RED, 2, GetX, GetY, 0, GetAngleToPlayer+10, 500, 20, RED60, 60)];
        }
        if(difficulty=="fuckingwhat"){
          ascent(i in 0..15){
            lasers = lasers ~ [ColorLaser_Create(RED, 2, GetX, GetY, 0, GetAngleToPlayer+i*24, 500, 20, RED60, 60)];
          }
        }
      }
      
      if(count==360){
        let len = length(lasers);
        loop(len){
          ObjShot_FadeDelete(lasers[0]);
          lasers = erase(lasers, 0);
        }
        SetMovePosition01(GetX, GetClipMinY-50, 1);
      }
      
      if(count==600){
        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;
        let len = length(lasers);
        loop(len){
          ObjShot_FadeDelete(lasers[0]);
          lasers = erase(lasers, 0);
        }
        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(imgEnemy);
      if(drawCount%32==0){
        SetGraphicRect(0,0,37,34);
      }
      if(drawCount%32==8 || drawCount%32==24){
        SetGraphicRect(37,0,74,34);
      }
      if(drawCount%32==16){
        SetGraphicRect(74,0,111,34);
      }
      SetGraphicAngle(0, 0, 0);
      DrawGraphic(GetX, GetY);
      drawCount++;
    }
    // End of "real" @Drawloop.

  }
}