script_enemy_main {
  #include_function "lib\Ikareimu\Enemy.dnh"
  
  let frame = -60;
  let imgBoss = "script\Ikareimu\img\sprite\Marisa.png";
  let sfxShot="script\Ikareimu\sfx\ZUN\se_tan00.wav";
  let difficulty = GetCommonData("difficulty");
  @Initialize {
    IkareimuEnemy_Initialize;
    IkareimuEnemy_SetPolarity(NONE);
    LoadGraphic(imgBoss);
    
    SetLife(3000);
    SetTimer(50);
    SetInvincibility(120);
    SetEnemyMarker(true);
    
    SetMovePosition03(GetCenterX, GetClipMinY+120, 12, 8);
  }
  
  @MainLoop {
    IkareimuEnemy_SetCollisionA(GetX, GetY, 48);
    SetCollisionB(GetX, GetY, 24);
    
    if(frame==-1){
      SixWayShot(1.5, 150);
    }
    
    if(frame%75==0 && frame>=0 && difficulty=="easy"){
      PlaySE(sfxShot);
      let randomTilt = rand(0, 360);
      ascent(i in 0..20){
        CrissCrossShot(2, i*18+randomTilt, 1.5);
      }
    }
    
    if(frame%50==0 && frame>=0 && difficulty=="normal"){
      PlaySE(sfxShot);
      let randomTilt = rand(0, 360);
      ascent(i in 0..30){
        CrissCrossShot(2, i*12+randomTilt, 2.25);
      }
    }
    
    if(frame%40==0 && frame>=0 && difficulty=="hard"){
      PlaySE(sfxShot);
      let randomTilt = rand(0, 360);
      ascent(i in 0..36){
        CrissCrossShot(2, i*10+randomTilt, 2.25);
      }
    }
    
    if(frame%30==0 && frame>=0 && difficulty=="lunatic"){
      PlaySE(sfxShot);
      let randomTilt = rand(0, 360);
      ascent(i in 0..45){
        CrissCrossShot(2, i*8+randomTilt, 3);
      }
    }
    
    if(frame%25==0 && frame>=0 && difficulty=="fuckingwhat"){
      PlaySE(sfxShot);
      let randomTilt = rand(0, 360);
      ascent(i in 0..60){
        CrissCrossShot(2, i*6+randomTilt, 3.5);
      }
    }
    
    if(frame==360){
      SetMovePosition03(GetCenterX+rand(-100, 100), GetClipMinY+rand(90,120), 12, 8);
      frame=0;
    }
    
    yield;
    IkareimuEnemy_Run;
    frame++;
  }
  
  @Finalize {
    IkareimuEnemy_Finalize;
  }
  
  @DrawLoop {
    SetTexture(imgBoss);
    SetGraphicRect(0, 0, 64, 64);
    DrawGraphic(GetX, GetY);
  }
  
    task SixWayShot(speed, distance){
    let spin = 0;
    loop {
      if(difficulty=="easy" || difficulty=="normal"){
        ascent(i in 0..2){
          ColorShot_Create(RED,  GetX+cos(spin      )*distance, GetY+sin(spin      )*distance, speed, spin + 91-i*2,  RED58,  10);
          ColorShot_Create(BLUE, GetX+cos(spin + 60 )*distance, GetY+sin(spin + 60 )*distance, speed, spin + 151-i*2,  BLUE58, 10);
          ColorShot_Create(RED,  GetX+cos(spin + 120)*distance, GetY+sin(spin + 120)*distance, speed, spin + 211-i*2,  RED58,  10);
          ColorShot_Create(BLUE, GetX+cos(spin + 180)*distance, GetY+sin(spin + 180)*distance, speed, spin + 271-i*2,  BLUE58, 10);
          ColorShot_Create(RED,  GetX+cos(spin + 240)*distance, GetY+sin(spin + 240)*distance, speed, spin + 331-i*2, RED58,  10);
          ColorShot_Create(BLUE, GetX+cos(spin + 300)*distance, GetY+sin(spin + 300)*distance, speed, spin + 391-i*2, BLUE58, 10);
        }
        spin-=1.848;
        loop(3){yield;}
      }
      else {
        ColorShot_Create(RED,  GetX+cos(spin      )*distance, GetY+sin(spin      )*distance, speed, spin + 90,  RED59,  10);
        ColorShot_Create(BLUE, GetX+cos(spin + 60 )*distance, GetY+sin(spin + 60 )*distance, speed, spin + 150,  BLUE59, 10);
        ColorShot_Create(RED,  GetX+cos(spin + 120)*distance, GetY+sin(spin + 120)*distance, speed, spin + 210,  RED59,  10);
        ColorShot_Create(BLUE, GetX+cos(spin + 180)*distance, GetY+sin(spin + 180)*distance, speed, spin + 270,  BLUE59, 10);
        ColorShot_Create(RED,  GetX+cos(spin + 240)*distance, GetY+sin(spin + 240)*distance, speed, spin + 330, RED59,  10);
        ColorShot_Create(BLUE, GetX+cos(spin + 300)*distance, GetY+sin(spin + 300)*distance, speed, spin + 390, BLUE59, 10);
        spin-=1.848;
        loop(5){yield;}
      }
    }
  }
  
  task CrissCrossShot(speed, angle, angularRotation){
    let redShot = ColorShot_Create(RED, GetX, GetY, speed, angle, RED58, 10);
    let blueShot = ColorShot_Create(BLUE, GetX, GetY, speed, angle, BLUE58, 10);
    loop(60) {
      if(Obj_BeDeleted(redShot) && Obj_BeDeleted(blueShot)){
        return;
      }
      if(!Obj_BeDeleted(redShot)){
        Obj_SetAngle(redShot, Obj_GetAngle(redShot)+angularRotation);
      }
      if(!Obj_BeDeleted(blueShot)){
        Obj_SetAngle(blueShot, Obj_GetAngle(blueShot)-angularRotation);
      }
      yield;
    }
    return;
  }
}