-- GPN Level

function level_size()
    return 40, 28
end

function level_koth_pos()
    return 20, 14
end

function level_init()
    world_dig(20, 14, TILE_PLAIN)
    world_dig(12, 4, TILE_PLAIN)
    world_dig(11, 4, TILE_PLAIN)
    world_dig(10, 4, TILE_PLAIN)
    world_dig(9, 4, TILE_PLAIN)
    world_dig(8, 4, TILE_PLAIN)
    world_dig(7, 5, TILE_PLAIN)
    world_dig(8, 5, TILE_PLAIN)
    world_dig(9, 5, TILE_PLAIN)
    world_dig(10, 5, TILE_PLAIN)
    world_dig(11, 5, TILE_PLAIN)
    world_dig(6, 6, TILE_PLAIN)
    world_dig(7, 6, TILE_PLAIN)
    world_dig(8, 6, TILE_PLAIN)
    world_dig(9, 6, TILE_PLAIN)
    world_dig(5, 7, TILE_PLAIN)
    world_dig(6, 7, TILE_PLAIN)
    world_dig(7, 7, TILE_PLAIN)
    world_dig(8, 7, TILE_PLAIN)
    world_dig(4, 8, TILE_PLAIN)
    world_dig(5, 8, TILE_PLAIN)
    world_dig(6, 8, TILE_PLAIN)
    world_dig(4, 9, TILE_PLAIN)
    world_dig(5, 9, TILE_PLAIN)
    world_dig(6, 10, TILE_PLAIN)
    world_dig(7, 10, TILE_PLAIN)
    world_dig(5, 10, TILE_PLAIN)
    world_dig(5, 11, TILE_PLAIN)
    world_dig(6, 11, TILE_PLAIN)
    world_dig(6, 12, TILE_PLAIN)
    world_dig(5, 12, TILE_PLAIN)
    world_dig(6, 13, TILE_PLAIN)
    world_dig(6, 14, TILE_PLAIN)
    world_dig(5, 14, TILE_PLAIN)
    world_dig(5, 13, TILE_PLAIN)
    world_dig(6, 15, TILE_PLAIN)
    world_dig(5, 15, TILE_PLAIN)
    world_dig(6, 16, TILE_PLAIN)
    world_dig(5, 16, TILE_PLAIN)
    world_dig(6, 17, TILE_PLAIN)
    world_dig(6, 18, TILE_PLAIN)
    world_dig(7, 18, TILE_PLAIN)
    world_dig(7, 19, TILE_PLAIN)
    world_dig(6, 19, TILE_PLAIN)
    world_dig(7, 20, TILE_PLAIN)
    world_dig(6, 20, TILE_PLAIN)
    world_dig(8, 21, TILE_PLAIN)
    world_dig(7, 21, TILE_PLAIN)
    world_dig(8, 20, TILE_PLAIN)
    world_dig(9, 20, TILE_PLAIN)
    world_dig(9, 21, TILE_PLAIN)
    world_dig(9, 22, TILE_PLAIN)
    world_dig(8, 22, TILE_PLAIN)
    world_dig(10, 22, TILE_PLAIN)
    world_dig(10, 23, TILE_PLAIN)
    world_dig(10, 21, TILE_PLAIN)
    world_dig(11, 21, TILE_PLAIN)
    world_dig(11, 22, TILE_PLAIN)
    world_dig(12, 20, TILE_PLAIN)
    world_dig(12, 21, TILE_PLAIN)
    world_dig(13, 20, TILE_PLAIN)
    world_dig(13, 19, TILE_PLAIN)
    world_dig(14, 19, TILE_PLAIN)
    world_dig(14, 20, TILE_PLAIN)
    world_dig(14, 21, TILE_PLAIN)
    world_dig(13, 21, TILE_PLAIN)
    world_dig(13, 18, TILE_PLAIN)
    world_dig(14, 18, TILE_PLAIN)
    world_dig(13, 17, TILE_PLAIN)
    world_dig(13, 16, TILE_PLAIN)
    world_dig(14, 16, TILE_PLAIN)
    world_dig(14, 17, TILE_PLAIN)
    world_dig(13, 15, TILE_PLAIN)
    world_dig(13, 14, TILE_PLAIN)
    world_dig(14, 14, TILE_PLAIN)
    world_dig(14, 15, TILE_PLAIN)
    world_dig(12, 15, TILE_PLAIN)
    world_dig(12, 14, TILE_PLAIN)
    world_dig(11, 15, TILE_PLAIN)
    world_dig(11, 14, TILE_PLAIN)
    world_dig(12, 5, TILE_PLAIN)
    world_dig(13, 4, TILE_PLAIN)
    world_dig(13, 5, TILE_PLAIN)
    world_dig(13, 6, TILE_PLAIN)
    world_dig(14, 5, TILE_PLAIN)
    world_dig(14, 6, TILE_PLAIN)
    world_dig(15, 7, TILE_PLAIN)
    world_dig(17, 4, TILE_PLAIN)
    world_dig(18, 4, TILE_PLAIN)
    world_dig(18, 5, TILE_PLAIN)
    world_dig(17, 5, TILE_PLAIN)
    world_dig(18, 6, TILE_PLAIN)
    world_dig(18, 7, TILE_PLAIN)
    world_dig(19, 7, TILE_PLAIN)
    world_dig(19, 8, TILE_PLAIN)
    world_dig(19, 9, TILE_PLAIN)
    world_dig(18, 9, TILE_PLAIN)
    world_dig(18, 8, TILE_PLAIN)
    world_dig(18, 10, TILE_PLAIN)
    world_dig(17, 9, TILE_PLAIN)
    world_dig(17, 8, TILE_PLAIN)
    world_dig(19, 10, TILE_PLAIN)
    world_dig(19, 11, TILE_PLAIN)
    world_dig(18, 11, TILE_PLAIN)
    world_dig(19, 12, TILE_PLAIN)
    world_dig(19, 13, TILE_PLAIN)
    world_dig(19, 14, TILE_PLAIN)
    world_dig(18, 14, TILE_PLAIN)
    world_dig(18, 13, TILE_PLAIN)
    world_dig(19, 15, TILE_PLAIN)
    world_dig(19, 16, TILE_PLAIN)
    world_dig(20, 15, TILE_PLAIN)
    world_dig(20, 16, TILE_PLAIN)
    world_dig(20, 17, TILE_PLAIN)
    world_dig(20, 18, TILE_PLAIN)
    world_dig(19, 18, TILE_PLAIN)
    world_dig(19, 17, TILE_PLAIN)
    world_dig(21, 17, TILE_PLAIN)
    world_dig(21, 18, TILE_PLAIN)
    world_dig(21, 19, TILE_PLAIN)
    world_dig(20, 19, TILE_PLAIN)
    world_dig(20, 20, TILE_PLAIN)
    world_dig(19, 20, TILE_PLAIN)
    world_dig(19, 19, TILE_PLAIN)
    world_dig(20, 21, TILE_PLAIN)
    world_dig(19, 21, TILE_PLAIN)
    world_dig(20, 22, TILE_PLAIN)
    world_dig(19, 4, TILE_PLAIN)
    world_dig(20, 4, TILE_PLAIN)
    world_dig(21, 4, TILE_PLAIN)
    world_dig(22, 4, TILE_PLAIN)
    world_dig(22, 5, TILE_PLAIN)
    world_dig(23, 5, TILE_PLAIN)
    world_dig(24, 5, TILE_PLAIN)
    world_dig(24, 6, TILE_PLAIN)
    world_dig(25, 6, TILE_PLAIN)
    world_dig(25, 7, TILE_PLAIN)
    world_dig(25, 8, TILE_PLAIN)
    world_dig(25, 9, TILE_PLAIN)
    world_dig(25, 10, TILE_PLAIN)
    world_dig(25, 11, TILE_PLAIN)
    world_dig(25, 12, TILE_PLAIN)
    world_dig(24, 12, TILE_PLAIN)
    world_dig(23, 12, TILE_PLAIN)
    world_dig(22, 12, TILE_PLAIN)
    world_dig(21, 12, TILE_PLAIN)
    world_dig(20, 12, TILE_PLAIN)
    world_dig(20, 13, TILE_PLAIN)
    world_dig(21, 13, TILE_PLAIN)
    world_dig(24, 11, TILE_PLAIN)
    world_dig(24, 10, TILE_PLAIN)
    world_dig(24, 9, TILE_PLAIN)
    world_dig(24, 8, TILE_PLAIN)
    world_dig(24, 7, TILE_PLAIN)
    world_dig(23, 6, TILE_PLAIN)
    world_dig(21, 5, TILE_PLAIN)
    world_dig(20, 5, TILE_PLAIN)
    world_dig(19, 5, TILE_PLAIN)
    world_dig(25, 22, TILE_PLAIN)
    world_dig(25, 21, TILE_PLAIN)
    world_dig(25, 20, TILE_PLAIN)
    world_dig(26, 19, TILE_PLAIN)
    world_dig(26, 18, TILE_PLAIN)
    world_dig(26, 17, TILE_PLAIN)
    world_dig(26, 16, TILE_PLAIN)
    world_dig(27, 16, TILE_PLAIN)
    world_dig(27, 15, TILE_PLAIN)
    world_dig(27, 14, TILE_PLAIN)
    world_dig(27, 13, TILE_PLAIN)
    world_dig(27, 12, TILE_PLAIN)
    world_dig(27, 11, TILE_PLAIN)
    world_dig(27, 10, TILE_PLAIN)
    world_dig(27, 9, TILE_PLAIN)
    world_dig(27, 8, TILE_PLAIN)
    world_dig(28, 8, TILE_PLAIN)
    world_dig(28, 7, TILE_PLAIN)
    world_dig(28, 6, TILE_PLAIN)
    world_dig(28, 5, TILE_PLAIN)
    world_dig(29, 6, TILE_PLAIN)
    world_dig(29, 7, TILE_PLAIN)
    world_dig(29, 8, TILE_PLAIN)
    world_dig(29, 9, TILE_PLAIN)
    world_dig(30, 10, TILE_PLAIN)
    world_dig(30, 11, TILE_PLAIN)
    world_dig(30, 12, TILE_PLAIN)
    world_dig(30, 13, TILE_PLAIN)
    world_dig(30, 14, TILE_PLAIN)
    world_dig(31, 15, TILE_PLAIN)
    world_dig(31, 16, TILE_PLAIN)
    world_dig(31, 17, TILE_PLAIN)
    world_dig(31, 18, TILE_PLAIN)
    world_dig(32, 18, TILE_PLAIN)
    world_dig(32, 19, TILE_PLAIN)
    world_dig(32, 20, TILE_PLAIN)
    world_dig(32, 21, TILE_PLAIN)
    world_dig(33, 21, TILE_PLAIN)
    world_dig(33, 22, TILE_PLAIN)
    world_dig(31, 14, TILE_PLAIN)
    world_dig(31, 13, TILE_PLAIN)
    world_dig(31, 12, TILE_PLAIN)
    world_dig(30, 9, TILE_PLAIN)
    world_dig(30, 8, TILE_PLAIN)
    world_dig(28, 9, TILE_PLAIN)
    world_dig(27, 17, TILE_PLAIN)
    world_dig(27, 18, TILE_PLAIN)
    world_dig(26, 20, TILE_PLAIN)
    world_dig(26, 21, TILE_PLAIN)
    world_dig(28, 10, TILE_PLAIN)
    world_dig(28, 11, TILE_PLAIN)
    world_dig(34, 21, TILE_PLAIN)
    world_dig(34, 20, TILE_PLAIN)
    world_dig(35, 19, TILE_PLAIN)
    world_dig(35, 18, TILE_PLAIN)
    world_dig(35, 17, TILE_PLAIN)
    world_dig(35, 16, TILE_PLAIN)
    world_dig(35, 15, TILE_PLAIN)
    world_dig(35, 14, TILE_PLAIN)
    world_dig(36, 14, TILE_PLAIN)
    world_dig(36, 13, TILE_PLAIN)
    world_dig(36, 12, TILE_PLAIN)
    world_dig(36, 11, TILE_PLAIN)
    world_dig(36, 10, TILE_PLAIN)
    world_dig(36, 9, TILE_PLAIN)
    world_dig(36, 8, TILE_PLAIN)
    world_dig(36, 7, TILE_PLAIN)
    world_dig(36, 6, TILE_PLAIN)
    world_dig(36, 5, TILE_PLAIN)
    world_dig(35, 7, TILE_PLAIN)
    world_dig(35, 8, TILE_PLAIN)
    world_dig(35, 9, TILE_PLAIN)
    world_dig(35, 10, TILE_PLAIN)
    world_dig(35, 11, TILE_PLAIN)
    world_dig(36, 15, TILE_PLAIN)
    world_dig(34, 19, TILE_PLAIN)
    world_dig(5, 23, TILE_PLAIN)
    world_dig(6, 23, TILE_PLAIN)
    world_dig(7, 23, TILE_PLAIN)
    world_dig(8, 23, TILE_PLAIN)
    world_dig(9, 23, TILE_PLAIN)
    world_dig(11, 23, TILE_PLAIN)
    world_dig(12, 23, TILE_PLAIN)
    world_dig(13, 23, TILE_PLAIN)
    world_dig(14, 23, TILE_PLAIN)
    world_dig(15, 23, TILE_PLAIN)
    world_dig(16, 23, TILE_PLAIN)
    world_dig(17, 23, TILE_PLAIN)
    world_dig(18, 23, TILE_PLAIN)
    world_dig(19, 23, TILE_PLAIN)
    world_dig(20, 23, TILE_PLAIN)
    world_dig(21, 23, TILE_PLAIN)
    world_dig(22, 23, TILE_PLAIN)
    world_dig(23, 23, TILE_PLAIN)
    world_dig(24, 23, TILE_PLAIN)
    world_dig(25, 23, TILE_PLAIN)
    world_dig(26, 23, TILE_PLAIN)
    world_dig(27, 23, TILE_PLAIN)
    world_dig(28, 23, TILE_PLAIN)
    world_dig(29, 23, TILE_PLAIN)
    world_dig(30, 23, TILE_PLAIN)
    world_dig(31, 23, TILE_PLAIN)
    world_dig(32, 23, TILE_PLAIN)
    world_dig(33, 23, TILE_PLAIN)
    world_dig(34, 23, TILE_PLAIN)
    world_dig(35, 23, TILE_PLAIN)
    world_dig(37, 4, TILE_PLAIN)
    world_dig(36, 4, TILE_PLAIN)
    world_dig(35, 4, TILE_PLAIN)
    world_dig(34, 4, TILE_PLAIN)
    world_dig(33, 4, TILE_PLAIN)
    world_dig(32, 4, TILE_PLAIN)
    world_dig(32, 5, TILE_PLAIN)
    world_dig(31, 5, TILE_PLAIN)
    world_dig(30, 5, TILE_PLAIN)
    world_dig(29, 5, TILE_PLAIN)
    world_dig(27, 5, TILE_PLAIN)
    world_dig(26, 5, TILE_PLAIN)
    world_dig(25, 5, TILE_PLAIN)
    world_dig(25, 4, TILE_PLAIN)
    world_dig(24, 4, TILE_PLAIN)
    world_dig(23, 4, TILE_PLAIN)
    world_dig(16, 4, TILE_PLAIN)
    world_dig(15, 4, TILE_PLAIN)
    world_dig(14, 4, TILE_PLAIN)
    world_dig(7, 4, TILE_PLAIN)
    world_dig(6, 4, TILE_PLAIN)
    world_dig(5, 4, TILE_PLAIN)
    world_dig(4, 4, TILE_PLAIN)
    world_dig(4, 3, TILE_PLAIN)
    world_dig(3, 3, TILE_PLAIN)
    world_dig(3, 4, TILE_PLAIN)
    world_dig(2, 4, TILE_PLAIN)
    world_dig(1, 4, TILE_PLAIN)
    world_dig(38, 4, TILE_PLAIN)
    world_dig(36, 23, TILE_PLAIN)
    world_dig(37, 23, TILE_PLAIN)
    world_dig(38, 23, TILE_PLAIN)
    world_dig(4, 23, TILE_PLAIN)
    world_dig(3, 23, TILE_PLAIN)
    world_dig(2, 23, TILE_PLAIN)
    world_dig(1, 23, TILE_PLAIN)
    world_dig(15, 6, TILE_PLAIN)

    world_make_border(TILE_GFX_BORDER)

    food_spawner = {}
    for s = 0, 10 do
        local dx, dy = world_find_digged()
        food_spawner[s] = { x = dx,
                            y = dy,
                            r = math.random(3),
                            a = math.random(100) + 30,
                            i = math.random(1000) + 1000,
                            n = game_time() }
        world_add_food(food_spawner[s].x, 
                       food_spawner[s].y, 
                       10000)
    end

    last_food = game_time()
end

function level_tick()
    if game_time() > last_food + 10000 then
        for n, spawner in pairs(food_spawner) do
            if game_time() > spawner.n then 
                world_add_food(spawner.x + math.random(spawner.r * 2 + 1) - spawner.r,
                               spawner.y + math.random(spawner.r * 2 + 1) - spawner.r,
                               spawner.a)
                spawner.n = spawner.n + spawner.i                               
            end
        end
    end
end
