function drop_eggs()

  
  if table.getn(egg_splatterx) > 0 then
    for i = 1, table.getn(egg_splatterx) do
      egg_splatter_time[i] = egg_splatter_time[i] - 1
      if egg_splatter_time[i] <= 0 then table.insert(egg_splatter_to_be_removed,i) end
    end
  end

  if chickens_on_level > 0 then
    for i = 1,chickens_on_level do
      if math.random(300) == 1 and level ~= 3 and level ~= 6 and level ~= 9 then drop_egg(i) end
    end
  end

  if table.getn(eggx) > 0 then
    for i = 1,table.getn(eggx) do
      eggy[i] = eggy[i] + egg_move_speed[i]

      if eggy[i] >= 255 then create_egg_splatter(i) table.insert(eggs_to_be_removed,i) end
    end
  end
  
  remove_egg_splatter()
  remove_eggs()
end

function create_egg_splatter(egg_number)
  table.insert(egg_splatterx,eggx[egg_number]-5)
  table.insert(egg_splattery,eggy[egg_number])
  table.insert(egg_splatter_time,egg_splatter_time_max)
end

function remove_egg_splatter()
  egg_splatter_to_be_removed = sort(egg_splatter_to_be_removed)
  if table.getn(egg_splatter_to_be_removed) > 0 then
    for i = 1,table.getn(egg_splatter_to_be_removed) do
      table.remove(egg_splatterx,egg_splatter_to_be_removed[i]) 
      table.remove(egg_splattery,egg_splatter_to_be_removed[i]) 
      table.remove(egg_splatter_time,egg_splatter_to_be_removed[i])
    end
  end
  egg_splatter_to_be_removed = {}
end

function drop_egg(chicken_number)
  table.insert(eggx,chickenx[chicken_number] + 20)
  table.insert(eggy,chickeny[chicken_number] + 40)
  table.insert(egg_move_speed,(math.random(200)/100) + 1)
end

function remove_eggs()
  eggs_to_be_removed = sort(eggs_to_be_removed)
  if table.getn(eggs_to_be_removed) > 0 then
    for i = 1,table.getn(eggs_to_be_removed) do
      table.remove(eggx,eggs_to_be_removed[i]) 
      table.remove(eggy,eggs_to_be_removed[i]) 
      table.remove(egg_move_speed,eggs_to_be_removed[i])
    end
  end
  eggs_to_be_removed = {}
end
