--- shoot balls for 2s
--- wait 1s
--- destroy balls? ig
local function dissolve(entity)
  entity.Sprite:Play("diseappear")
end

local function land(entity)
  entity.Sprite:Play("splatter")
  playSound("event:/CC/CC_HollowKnight/SFX/Boss SFX/InfectionImpact",entity.Center)
  entity.Speed = vector2(0, 0)
  entity.Collider = getHitbox(16, 4, 0, -4)
  entity:Add(getEntityTimer(1, dissolve))
  entity:Add(getEntityTimer(1))
end

local function getBlob(dir, strength)
  local blob = getNewBasicAttackActor(puppet.Position, getHitbox(10, 10, 0, -10), "infectedBall", 0.85, 200) --change sprite to that of infection blob
  blob.Sprite:Play("spin")
  blob.Speed = normalize(dir, strength * 4)
  blob:Add(getEntityChecker(
    function ()
      return blob.Grounded
    end, land)
  )
  return blob
end

local function a2V(angle)
  local rad = math.rad(angle)
  local result = vector2(math.cos(rad) * puppet.Facing, -math.sin(rad))
  return result
end

--format {angle, speed}
--(degrees, 0� to right)
local blobs = {
  {140, 105}, {145, 95}, {150, 85}, {155, 75}, {160, 65}, {165, 55}, {175, 35}, {185, 15} --front
}

function onBegin()
  setFlag("hk_change_to_no_head", true)
  playPuppetAnim("infectionBurst")
  playSound("event:/CC/CC_HollowKnight/SFX/Boss SFX/THK_Burst",puppet.Center)
  for _, dir in ipairs(blobs) do
    local offset = a2V(dir[1])
    --log("CCCC")
    local blob = getBlob(offset, dir[2])
    addEntity(blob)
    wait(0.25)
  end
  playPuppetAnim("idle")
  wait(1)

  setFlag("hk_change_to_main", true)
end