script_enemy_main {
  #include_function "lib\Ikareimu\Enemy.dnh"
  
  let count=0;
  let imgEnemy="script\Ikareimu\img\sprite\FairyBlueSmall.png";
  let sfxShot="script\Ikareimu\sfx\ZUN\se_tan00.wav";
  let LastPosX=GetX;
  let difficulty = GetCommonData("difficulty");
  
  let direction;
  @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(10030);
    if(GetX < GetCenterX){
      direction = "right";
    }
    if(GetX > GetCenterX){
      direction = "left";
    }
    SetMovePosition03(GetX, GetY+210, 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%90==30 && GetY>32 && difficulty != "fuckingwhat"){
        PlaySE(sfxShot);
        if(difficulty == "easy"){
          ascent(i in 0..3){
            ColorShot_Create(BLUE, GetX, GetY, 2, GetAngleToPlayer-5+i*5, BLUE01, 10);
          }
        }
        if(difficulty == "normal"){
          ascent(i in 0..5){
            ColorShot_Create(BLUE, GetX, GetY, 2, GetAngleToPlayer-10+i*5, BLUE01, 10);
          }
        }
        if(difficulty == "hard"){
          ascent(i in 0..5){
            ColorShot_Create(BLUE, GetX, GetY, 2, GetAngleToPlayer-10+i*5, BLUE01, 10);
            ColorShot_Create(BLUE, GetX, GetY, 3, GetAngleToPlayer-10+i*5, BLUE01, 10);
          }
        }
        if(difficulty == "lunatic"){
          ascent(i in 0..7){
            ColorShot_Create(BLUE, GetX, GetY, 2, GetAngleToPlayer-15+i*5, BLUE01, 10);
            ColorShot_Create(BLUE, GetX, GetY, 3, GetAngleToPlayer-15+i*5, BLUE01, 10);
          }
        }
      }
      if(count%45==30 && GetY>32 && difficulty == "fuckingwhat"){
        PlaySE(sfxShot);
        ascent(i in 0..7){
          ColorShot_Create(BLUE, GetX, GetY, 1, GetAngleToPlayer-15+i*5, BLUE01, 10);
          ColorShot_Create(BLUE, GetX, GetY, 2, GetAngleToPlayer-15+i*5, BLUE01, 10);
          ColorShot_Create(BLUE, GetX, GetY, 3, GetAngleToPlayer-15+i*5, BLUE01, 10);
        }
      }
      
      if(count==120){
        if(direction == "right"){
          SetMovePositionHermite(GetX+100, GetY-300, 300, 90, 50, 270, 240);
        }
        if(direction == "left"){
          SetMovePositionHermite(GetX-100, GetY-300, 300, 90, 50, 270, 240);
        }
      }
      
      if(count==360){
        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){
      let xDiff = GetX-LastPosX;
      SetTexture(imgEnemy);
      if(xDiff<0.1 || xDiff>-0.1){
        SetGraphicRect(24,0,48,26);
      }
      if(xDiff>=0.1){
        SetGraphicRect(48,0,72,26);
      }
      if(xDiff<=-0.1){
        SetGraphicRect(0,0,24,26);
      }
      SetGraphicAngle(0, 0, 0);
      DrawGraphic(GetX,GetY);
      LastPosX = GetX;
    }
    // End of "real" @Drawloop.

  }
}