script_enemy_main {
  #include_function ".\bosslib\Boss.dnh"
  let imgBoss = GetCurrentScriptDirectory ~ "img\wriggle.png";
  @Initialize {
    InitializeStbBoss;
    
    LoadGraphic(imgBoss);
    SetTexture(imgBoss);
    SetGraphicRect(0, 0, 48, 64);
    
    SetX(GetClipMinX);
    SetY(GetClipMinY);
    SetStbMovePosition03(GetCenterX, GetClipMinY+130, 20, 8);
    
    SetStbTimer(60);
    Attack;
  }
  
  @MainLoop {
    yield;
  }
  
  @DrawLoop {
    DrawGraphic(GetX, GetY);
  }
  
  @Finalize {
  }
  
  task Attack {
    Wait(72);
    loop {
      loop {
        CurvyBullets(rand(0, 360));
        Wait(57);
        NiceShot;
        Wait(15);
        if(GetCurrentPicture > 1){ break; }
        SetStbMovePosition03(GetCenterX+rand(40, 80), GetClipMinY+rand(120, 200), 20, 5);
        Wait(72);
        CurvyBullets(rand(0, 360));
        Wait(57);
        NiceShot;
        Wait(15);
        if(GetCurrentPicture > 1){ break; }
        SetStbMovePosition03(GetCenterX-rand(40, 80), GetClipMinY+rand(120, 200), 20, 5);
        Wait(72);
      }
      loop {
        SetStbMovePosition03(GetCenterX-rand(40, 80), GetClipMinY+rand(120, 200), 20, 5);
        let random = rand(0, 360);
        Wait(72);
        CurvyBullets(random);
        Wait(36);
        StraightBullets(GetAngleToPlayer);
        Wait(36);
        CurvyBullets(random);
        Wait(57);
        NiceShot;
        Wait(15);
        SetStbMovePosition03(GetCenterX+rand(40, 80), GetClipMinY+rand(120, 200), 20, 5);
        random = rand(0, 360);
        Wait(72);
        CurvyBullets(random);
        Wait(36);
        StraightBullets(GetAngleToPlayer);
        Wait(36);
        CurvyBullets(random);
        Wait(57);
        NiceShot;
        Wait(15);
      }
    }
  }
  
  task CurvyBullets(angle){
    loop(12){
      ascent(i in 0..10){
        CurvyBullet(GetX, GetY, 3, angle+i*36, YELLOW01, 10);
      }
      CreateStbDelay(GetX, GetY, YELLOW, 10);
      Wait(6);
    }
  }
  
  task StraightBullets(angle){
    loop(12){
      ascent(i in 0..6){
        ObjStbShot_Initialize(GetX, GetY, 3, angle+i*60, YELLOW02, 10, 50, 12, YELLOW);
      }
      CreateStbDelay(GetX, GetY, YELLOW, 10);
      Wait(9);
    }
  }
  
  task CurvyBullet(x, y, speed, angle, graphic, delay){
    let obj = ObjStbShot_Initialize(x, y, speed, angle, graphic, delay, 50, 8, YELLOW);
    Wait(delay);
    loop(30){
      ObjStbShot_SetAngle(obj, ObjStbShot_GetAngle(obj)+1.5);
      Wait(1);
    }
    Wait(4);
    loop(60){
      ObjStbShot_SetAngle(obj, ObjStbShot_GetAngle(obj)-1.5);
      Wait(1);
    }
    Wait(4);
    loop(60){
      ObjStbShot_SetAngle(obj, ObjStbShot_GetAngle(obj)+1.5);
      Wait(1);
    }
    Wait(4);
    loop(60){
      ObjStbShot_SetAngle(obj, ObjStbShot_GetAngle(obj)-1.5);
      Wait(1);
    }
  }
}