script_enemy_main {
  #include_function ".\lib\enemy.dnh"
  #include_function ".\lib\utusho_animation.dnh"
  Spawned = true;
  @Initialize {
    InitializeEnemy;
    InitializeUtsuhoAnimation;
    SetLife(3000);
    SetDamageRate(0, 0);
    mainTask;
  }
  
  @MainLoop {
    SetCollisionA(GetX, GetY, 48);
    SetCollisionB(GetX, GetY, 32);
    yield;
  }
  
  @DrawLoop {
    DrawUtsuho;
  }
  
  @Finalize {
    DeleteGraphic(imgUtsuho);
    FinalizeEnemy;
  }
  
  task mainTask {
    Wait(60);
    loop {
      Move(180, 10, 180);
      SetDamageRate(75, 75);
      ShootLines(180);
      Wait(210);
      ShootBubbles;
      Wait(120);
      Move(0, 10, 180);
      ShootLines(0);
      Wait(210);
      ShootBubbles;
      Wait(120);
    }
  }
  
  task ShootBubbles {
    PlaySE(sfxShot);
    MoveTowardPlayer;
    ascent(i in -1..2){
      ascent(j in 1..6){
        WrapObjShot_Initialize(GetX, GetY, j*0.7, GetAngleToPlayer+i*45, 229, 10, 150);
      }
    }
    
    task MoveTowardPlayer {    
      SetWrapSpeed(2);
      loop(119){
        SetWrapAngle(GetAngleToPlayer);
        yield;
      }
    }
  }
  
  task ShootLines(angle){
    loop(30){
      PlaySE(sfxShot);
      ascent(i in 1..11){
        WrapObjShot_Initialize(GetX, GetY, i*0.5, angle+90, 201, 10, 180);
        WrapObjShot_Initialize(GetX, GetY, i*0.5, angle-90, 201, 10, 180);
      }
      Wait(6);
    }
  }
  
  task Move(angle, maxspeed, duration){
    SetWrapAngle(angle);
    ascent(i in 0..floor(duration/4)){
      SetWrapSpeed(maxspeed/floor(duration/4)*i);
      yield;
    }
    SetWrapSpeed(maxspeed);
    Wait(floor(duration/2));
    descent(i in 0..floor(duration/4)){
      SetWrapSpeed(maxspeed/floor(duration/4)*i);
      yield;
    }
    SetWrapSpeed(0);
  }
}