LoadedObjects = {}

-- level functions
function LoadedObjects.drawCollisions()
	for _, ladder in pairs(LoadedObjects.Collisions) do
		ladder:draw(1)
	end

	for _, platform in pairs(LoadedObjects.Platforms) do
		if platform.is_disabled == true then platform:Draw(2) end
		if platform.is_disabled == false then platform:Draw(1) end
	end

	for _, ladder in pairs(LoadedObjects.Ladders) do
		ladder:draw(2)
	end

	for _, hazard in pairs(LoadedObjects.Hazards) do
		hazard:draw(1)
	end
end

-- returns true if theres a collision at that point
function isThereObjectAt(x,y,objectType)
	for _, object in pairs(objectType) do
		if object.is_disabled then
			-- Dont calculate if dissabled
		elseif x >= object.from.x
		and x <= object.to.x
		and y >= object.from.y
		and y <= object.to.y then
			object.is_colliding = true
			return true
		end
	end
	return false
end

function isThereCollisionAt(x,y)
	if	x >= 0 and x < #CollisionTable
	and y >= 0 and y < #CollisionTable[0] then
		return CollisionTable[math.floor(y)][math.floor(x)]
	end
	return false
end

-- flags
function setCollisionFlags()
	local Check = {
		LoadedObjects.Collisions,
		LoadedObjects.Ladders,
		LoadedObjects.Platforms,
		LoadedObjects.Hazards
	}
	for _, type in pairs(Check) do
		for _, object in pairs(type) do
			object.is_colliding = false
		end
	end
	for _, platform in pairs(LoadedObjects.Platforms) do
		if main_player.pos.y < platform.from.y then
			platform.is_disabled = false
		else
			platform.is_disabled = true
		end
	end
	for _, platform in pairs(LoadedObjects.Hazards) do
		if main_player.isOnGround then
			platform.is_disabled = true
		else
			platform.is_disabled = false
		end
	end
end
