#include "bird.lua"
#include "../../script/helpers/entity.lua"

is_bird_flew_away = nil
body = nil
joints = nil
wings = nil
sky_transform = nil
bird = nil

function init()
    is_bird_flew_away = false
    body = FindBody("body")
    joints = FindJoints()
    wings = FindBodies("wing")
    local sky_location = FindLocation("sky")
    sky_transform = GetLocationTransform(sky_location)
    Delete(sky_location)
    on_init()
end

function on_init()
    bird = birds:new()
    bird:Init(body, wings, joints, sky_transform)
    bird:SetVelAndImpulse(6, 10)
end

function handleCommand(str)
    if str == "quickload" then
        on_init()
    end
end

function update(dt)
    if is_bird_flew_away then return end

    is_bird_flew_away = bird:IsFlewAway()
    if is_bird_flew_away then
        cEntity:EnqueueDeletion()
        return
    end
    bird:Update(dt)
end
