#include "../../config/events.lua"

function init()
    pillars         = FindShapes("pillar")
    door            = FindBody("door")
    if door == 0 then return end
    
    local t         = GetBodyTransform(door)
    local pos       = VecAdd(t.pos, Vec(-2.8, -1.7, 0.0))
    new_door_t      = Transform(pos, QuatEuler(180.0, 180.0, -70.0))
end

function tick(dt)
    local player_lap = GetInt("level.playerlap")
    if player_lap == 1 and door > 0 then
        for i = 1, #pillars do
            Delete(pillars[i])
        end
        SetBodyTransform(door, new_door_t)
        SetBodyDynamic(door, false)
		TriggerEvent(EVENTS.SECOND_PHASE, 5)
    end
end