script_enemy_main {
  #include_function "lib\Ikareimu\Enemy.dnh"
  
  let frame = -240;
  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 sfxShot="script\Ikareimu\sfx\ZUN\se_tan00.wav";
  let sfxLaser="script\Ikareimu\sfx\ZUN\se_lazer00.wav";
  let difficulty = GetCommonData("difficulty");
  @Initialize {
    IkareimuEnemy_Initialize;
    IkareimuEnemy_SetPolarity(NONE);
    
    LoadGraphic(imgBoss);
    LoadGraphic(imgBG1);
    LoadGraphic(imgBG2);
    
    SetLife(600);
    SetDamageRate(20, 20);
    SetInvincibility(240);
    SetTimer(60);

    SetMovePosition03(GetCenterX, GetClipMinY+120, 12, 8);
  }
  
  @MainLoop {
    IkareimuEnemy_SetCollisionA(GetX, GetY, 48);
    SetCollisionB(GetX, GetY, 24);
    
    if(frame == -120){
      SetScore(50000);
      if(difficulty == "easy"){
        CutIn(YOUMU, "Love Sign " \" "Non-directional Laser ~Easy~" \", "", 0, 0, 0, 0);
      }
      if(difficulty == "normal"){
        CutIn(YOUMU, "Love Sign " \" "Non-directional Laser ~Normal~" \", "", 0, 0, 0, 0);
      }
      if(difficulty == "hard"){
        CutIn(YOUMU, "Love Sign " \" "Non-directional Laser ~Hard~" \", "", 0, 0, 0, 0);
      }
      if(difficulty == "lunatic"){
        CutIn(YOUMU, "Love Sign " \" "Non-directional Laser ~Lunatic~" \", "", 0, 0, 0, 0);
      }
      if(difficulty == "fuckingwhat"){
        CutIn(YOUMU, "Love Sign " \" "Non-directional Laser Net" \", "", 0, 0, 0, 0);
      }
    }
    
    if(frame == -1){
      PlaySE(sfxLaser);
      ascent(i in 0..4){
        RotatingLaser(22.5+i*90, 100, 0.375, RED);
        RotatingLaser(22.5+i*90, 100, -0.375, BLUE);
      }
    }

    if(difficulty=="easy"){
      if(frame == 240){
        PlaySE(sfxShot);
        ascent(i in 0..16){
          HomingRing(22.5*i, 3, RED);
        }
      }
      if(frame == 480){
        PlaySE(sfxShot);
        ascent(i in 0..16){
          HomingRing(22.5*i, 3, BLUE);
        }
        frame = 0;
      }
    }

    if(difficulty=="normal"){
      if(frame == 240){
        PlaySE(sfxShot);
        ascent(i in 0..20){
          HomingRing(18*i, 3.5, RED);
        }
      }
      if(frame == 480){
        PlaySE(sfxShot);
        ascent(i in 0..20){
          HomingRing(18*i, 3.5, BLUE);
        }
        frame = 0;
      }
    }

    if(difficulty=="hard"){
      if(frame == 180){
        PlaySE(sfxShot);
        ascent(i in 0..20){
          HomingRing(18*i, 3.5, RED);
        }
      }
      if(frame == 360){
        PlaySE(sfxShot);
        ascent(i in 0..20){
          HomingRing(18*i, 3.5, BLUE);
        }
        frame = 0;
      }
    }

    if(difficulty=="lunatic"){
      if(frame == 180){
        PlaySE(sfxShot);
        ascent(i in 0..24){
          HomingRing(15*i, 4, RED);
        }
      }
      if(frame == 360){
        PlaySE(sfxShot);
        ascent(i in 0..24){
          HomingRing(15*i, 4, BLUE);
        }
        frame = 0;
      }
    }

    if(difficulty=="fuckingwhat"){
      if(frame == 120){
        PlaySE(sfxShot);
        ascent(i in 0..30){
          HomingRing(12*i, 4.5, RED);
        }
      }
      if(frame == 240){
        PlaySE(sfxShot);
        ascent(i in 0..30){
          HomingRing(12*i, 4.5, BLUE);
        }
        frame = 0;
      }
    }
    
    yield ;
    IkareimuEnemy_Run;
    frame++;
    spellbgcount+=5;
  }
  
  @DrawLoop {
    SetTexture(imgBoss);
    SetGraphicRect(0, 0, 64, 64);
    DrawGraphic(GetX, GetY);
  }
  
  @Finalize {
    IkareimuEnemy_Finalize;
  }
  
  @BackGround {
    SetTexture(imgBG1);
    SetGraphicRect(0, 0, 384, 448);
    DrawGraphic(GetCenterX, GetCenterY);
    SetTexture(imgBG2);
    SetGraphicRect(-100, 0+spellbgcount, 500, 700+spellbgcount);
    SetGraphicScale(0.7, 0.7);
    SetAlpha(100);
    DrawGraphic(GetCenterX, GetCenterY);
    SetGraphicScale(1, 1);
    SetAlpha(255);
  }
  
  task RotatingLaser(angle, distance, angularvelocity, col){
    let obj;
    let lasercount = -120;
    if(col == RED){
      obj = ColorLaser_Create(col, 2, GetX, GetY, 0, angle, 300, 30, RED60, 90);
    }
    else if(col == BLUE){
      obj = ColorLaser_Create(col, 2, GetX, GetY, 0, angle, 300, 30, BLUE60, 90);
    }
    while(!Obj_BeDeleted(obj)){
      Obj_SetAngle(obj, Obj_GetAngle(obj)+angularvelocity);
      Obj_SetPosition(obj, GetX+cos(Obj_GetAngle(obj))*distance, GetY+sin(Obj_GetAngle(obj))*distance);
      let interval;
      let speed;
      if(difficulty=="easy"){
        interval=30;
        speed = 2;
      }
      if(difficulty=="normal"){
        interval=20;
        speed = 2;
      }
      if(difficulty=="hard"){
        interval=16;
        speed = 2.5;
      }
      if(difficulty=="lunatic"){
        interval=12;
        speed = 2.5;
      }
      if(difficulty=="fuckingwhat"){
        interval=12;
        speed = 2.5;
        if(lasercount%interval == 0 && lasercount>=0){
        PlaySE(sfxShot);
          ColorShot_Create(RED, GetX+cos(Obj_GetAngle(obj))*distance, GetY+sin(Obj_GetAngle(obj))*distance, 
                     speed, Obj_GetAngle(obj)-225, RED59, 0);
        }
        if(lasercount%interval == interval/2 && lasercount>=0){
          ColorShot_Create(BLUE, GetX+cos(Obj_GetAngle(obj))*distance, GetY+sin(Obj_GetAngle(obj))*distance, 
                     speed, Obj_GetAngle(obj)-225, BLUE59, 0);
        }
        if(lasercount%interval == 0 && lasercount>=0){
          ColorShot_Create(RED, GetX+cos(Obj_GetAngle(obj))*distance, GetY+sin(Obj_GetAngle(obj))*distance, 
                     speed, Obj_GetAngle(obj)-135, RED59, 0);
        }
        if(lasercount%interval == interval/2 && lasercount>=0){
          ColorShot_Create(BLUE, GetX+cos(Obj_GetAngle(obj))*distance, GetY+sin(Obj_GetAngle(obj))*distance, 
                     speed, Obj_GetAngle(obj)-135, BLUE59, 0);
        }
      }
      if(lasercount%interval == 0 && lasercount>=0){
        PlaySE(sfxShot);
        ColorShot_Create(RED, GetX+cos(Obj_GetAngle(obj))*distance, GetY+sin(Obj_GetAngle(obj))*distance, 
                   speed, Obj_GetAngle(obj)-180, RED59, 0);
      }
      if(lasercount%interval == interval/2 && lasercount>=0){
        PlaySE(sfxShot);
        ColorShot_Create(BLUE, GetX+cos(Obj_GetAngle(obj))*distance, GetY+sin(Obj_GetAngle(obj))*distance, 
                   speed, Obj_GetAngle(obj)-180, BLUE59, 0);
      }
      lasercount++;
      yield ;
    }
    return ;
  }
  
  task HomingRing(angle, speed, col){
    let obj;
    if(col == RED){
      obj = ColorShot_Create(RED, GetX, GetY, speed, angle, RED58, 0);
    }
    if(col == BLUE){
      obj = ColorShot_Create(BLUE, GetX, GetY, speed, angle, BLUE58, 0);
    }
    loop(60){
      yield;
      Obj_SetSpeed(obj, Obj_GetSpeed(obj) - speed/60);
    }
    Obj_SetSpeed(obj, speed/2);
    Obj_SetAngle(obj, GetAngleFromPlayer(Obj_GetX(obj), Obj_GetY(obj))+180);
    return;
  }
}