script_enemy_main {
  #include_function "lib\Ikareimu\Enemy.dnh"
  
  let frame = -240;
  let stream = 1;
  let imgBoss = "script\Ikareimu\img\sprite\Marisa.png";
  let imgBG1 = "script\Ikareimu\img\spellbg\marisa1.png";
  let imgBG2 = "script\Ikareimu\img\spellbg\marisa2.png";
  let spellbgcount = 0;
  let bgshake = false;
  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");
  @Initialize {
    IkareimuEnemy_Initialize;
    IkareimuEnemy_SetPolarity(NONE);
    
    LoadGraphic(imgBoss);
    LoadGraphic(imgBG1);
    LoadGraphic(imgBG2);
    
    SetLife(350);
    SetDamageRate(20, 20);
    SetInvincibility(420);
    SetTimer(60);

    SetMovePosition03(GetCenterX, GetClipMinY+120, 12, 8);
  }
  
  @MainLoop {
    IkareimuEnemy_SetCollisionA(GetX, GetY, 48);
    SetCollisionB(GetX, GetY, 24);
    
    if(frame==-120){
      SetScore(100000);
      if(difficulty == "easy"){
        CutIn(YOUMU, "Love Sign " \" "Master Spark ~Easy~" \", "", 0, 0, 0, 0);
      }
      if(difficulty == "normal"){
        CutIn(YOUMU, "Love Sign " \" "Master Spark ~Normal~" \", "", 0, 0, 0, 0);
      }
      if(difficulty == "hard"){
        CutIn(YOUMU, "Love Sign " \" "Double Spark ~Hard~" \", "", 0, 0, 0, 0);
      }
      if(difficulty == "lunatic"){
        CutIn(YOUMU, "Love Sign " \" "Double Spark ~Lunatic~" \", "", 0, 0, 0, 0);
      }
      if(difficulty == "fuckingwhat"){
        CutIn(YOUMU, "Love Sign " \" "Non-directional Spark" \", "", 0, 0, 0, 0);
      }
    }
    
    if(frame%600==0){
      Concentration01(90);
    }
    
    if(frame%600==90){
      if(difficulty=="easy" || difficulty=="normal"){
        MasterSpark(GetX, GetY, GetAngleToPlayer);
      }
      else if(difficulty=="hard" || difficulty=="lunatic"){
        MasterSpark(GetX, GetY, GetAngleToPlayer-10);
        MasterSpark(GetX, GetY, GetAngleToPlayer+10);
      }
      else if(difficulty=="fuckingwhat"){
        MasterSpark(GetX, GetY, GetAngleToPlayer-10);
        MasterSpark(GetX, GetY, GetAngleToPlayer+10);
        MasterSpark(GetX, GetY, GetAngleToPlayer+110);
        MasterSpark(GetX, GetY, GetAngleToPlayer+130);
        MasterSpark(GetX, GetY, GetAngleToPlayer-110);
        MasterSpark(GetX, GetY, GetAngleToPlayer-130);
      }
    }
    
    if(frame%600==430){
      SetMovePosition03(GetCenterX+rand(-100, 100), GetClipMinY+rand(70, 140), 20, 4);
    }
    
    if(frame==210){
      CircleShotSpam;
    }
    
    yield;
    IkareimuEnemy_Run;
    spellbgcount+=5;
    frame++;
  }
  
  @Finalize {
    IkareimuEnemy_Finalize;
  }
  
  @DrawLoop {
    SetTexture(imgBoss);
    SetGraphicRect(0, 0, 64, 64);
    DrawGraphic(GetX, GetY);
  }
  
  @BackGround {
    let x = GetCenterX;
    let y = GetCenterY;
    if(bgshake==true){
      x += rand(-10, 10);
      y += rand(-10, 10);
    }
    SetTexture(imgBG1);
    SetGraphicRect(0, 0, 384, 448);
    SetGraphicScale(1.1, 1.1);
    DrawGraphic(x, y);
    SetTexture(imgBG2);
    SetGraphicRect(-100, 0+spellbgcount, 500, 700+spellbgcount);
    SetGraphicScale(0.7, 0.7);
    SetAlpha(100);
    DrawGraphic(x, y);
    SetGraphicScale(1, 1);
    SetAlpha(255);
  }
  
  task MasterSpark(x, y, angle){
    PlaySE(sfxLaser);
    CreateLaserA(0, x, y, 0, 50, MASTERSPARK, 90);
    SetLaserDataA(0, 0, angle, 0, 20, 0, 0);
    SetShotKillTime(0, 95);
    FireShot(0);
    loop(90){yield;}
    bgshake = true;
    PlaySE(sfxSpark);
    CreateLaserA(0, x+cos(angle-90)*20, y+sin(angle-90)*20, 550, 250, MASTERSPARK, 0);
    SetLaserDataA(0, 0, angle, 0, 0, 0, 0);
    SetShotKillTime(0, 240);
    FireShot(0);
    CreateLaserA(0, x+cos(angle+90)*20, y+sin(angle+90)*20, 550, 250, MASTERSPARK, 0);
    SetLaserDataA(0, 0, angle, 0, 0, 0, 0);
    SetShotKillTime(0, 240);
    FireShot(0);
    loop(240){yield;}
    bgshake = false;
  }
  
  task CircleShotSpam {
    let amount;
    let interval;
    if(difficulty=="easy"){
      amount = 24;
      interval = 75;
    }
    if(difficulty=="normal"){
      amount = 30;
      interval = 50;
    }
    if(difficulty=="hard"){
      amount = 36;
      interval = 40;
    }
    if(difficulty=="lunatic"){
      amount = 42;
      interval = 30;
    }
    if(difficulty=="fuckingwhat"){
      amount = 54;
      interval = 25;
    }
    loop {
      PlaySE(sfxShot);
      let randangle = rand(0, 360);
      ascent(i in 0..amount){
        ColorShot_Create(RED, GetX, GetY, 4, randangle+i*(360/amount), RED59, 10);
      }
      ascent(i in 0..amount/2){
        ColorShot_Create(RED, GetX, GetY, 2.5, randangle+i*(720/amount), RED59, 10);
        ColorShot_Create(BLUE, GetX, GetY, 2.5, randangle+i*(720/amount)+(360/amount), BLUE59, 10);
      }
      loop(interval){yield;}
      PlaySE(sfxShot);
      randangle = rand(0, 360);
      ascent(i in 0..amount){
        ColorShot_Create(BLUE, GetX, GetY, 4, randangle+i*(360/amount), BLUE59, 10);
      }
      ascent(i in 0..amount/2){
        ColorShot_Create(RED, GetX, GetY, 2.5, randangle+i*(720/amount), RED59, 10);
        ColorShot_Create(BLUE, GetX, GetY, 2.5, randangle+i*(720/amount)+(360/amount), BLUE59, 10);
      }
      loop(interval){yield;}
    }
  }
}