local calc = require("#monocle.calc")
local lua_helper = celeste.Mod.LuaCutscenes.LuaHelper
local ring = {}
local scene = getRoom()
local finishedRoutine = false
local lockPos = player.Center

local function makeCoroutine(func)
  return monocle.Coroutine(lua_helper.LuaCoroutineToIEnumerator(coroutine.create(func)))
end

local function makeDartRoutine(entity)
    return function()
        
    end
end



function onBegin()
    
    for i = 1, 6, 1 do

        ring[#ring+1] = getNewBasicAttackEntity(puppet.Center, getCircle(4), "badeline_projectile")
        
        ring[#ring]:add(makeCoroutine(makeDartRoutine(ring[#ring])))

        scene:add(ring[#ring])
    end

    

    local t = 0

    speedTweenTo(0, 0, 0.5)

    local lifetime = 0.5

    while lifetime > 0 do

        speedXTweenTo(getXSpeed()*5 + calc.ShakeVector(calc.Random).X*100, 0.1, monocle.Ease.QuadIn)
        
        if (puppet.Position.Y > player.Position.Y - 100) then
            speedYTweenTo(-150, 0.1, monocle.Ease.QuadIn)
        else
            speedYTweenTo(150, 0.1, monocle.Ease.QuadIn)
        end

        lifetime = lifetime - engine.deltaTime

        wait(0)
    end
end

function getXSpeed()
    return sign(-(puppet.Position.X - lockPos.X)) * 150
end

function getYSpeed()
    return sign((puppet.Position.X - lockPos.X + 16)) * 150
end

function sign(x)
    return (x<0 and -1) or 1
end  

function abs(x)
    return x * sign(x)
end

function randVector(max)
    return vector2(calc.NextFloat(calc.Random, max), calc.NextFloat(calc.Random, max))
end