Advertisement
Guest User

Untitled

a guest
May 26th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. local function fill(copyIN,x,y,fill)
  2.     local copy = copyIN
  3.     local tile = copyIN[y][x]
  4.     copy[y][x] = "a"
  5.     local filling = true
  6.     local m = {}
  7.     for i = 1, 19 do
  8.         m[i] = {}
  9.     end
  10.     for i = 1, 19 do
  11.         for j = 1, 51 do
  12.             m[i][j] = tile
  13.         end
  14.     end
  15.     while filling do
  16.         filling = false
  17.         for i = 1, 17 do
  18.             for j = 1, 51 do
  19.                 if copy[i][j] == "a" then
  20.                     for k = 1, 4 do
  21.                         if k == 1 and j < 51 then
  22.                             if copy[i][j + 1] == tile then
  23.                                 m[i][j + 1] = "a"
  24.                                 filling = true
  25.                             elseif copy[i][j + 1] == "a" then
  26.                                 m[i][j + 1] = fill
  27.                             end
  28.                         elseif k == 2 and i < 17 then
  29.                             if copy[i + 1][j] == tile then
  30.                                 m[i + 1][j] = "a"
  31.                                 filling = true
  32.                             elseif copy[i + 1][j] == "a" then
  33.                                 m[i + 1][j] = fill
  34.                             end
  35.                         elseif k == 3 and j > 1 then
  36.                             if copy[i][j - 1] == tile then
  37.                                 m[i][j - 1] = "a"
  38.                                 filling = true
  39.                             elseif copy[i][j - 1] == "a" then
  40.                                 m[i][j - 1] = fill
  41.                             end
  42.                         elseif k == 4 and i > 1 then
  43.                             if copy[i - 1][j] == tile then
  44.                                 m[i - 1][j] = "a"
  45.                                 filling = true
  46.                             elseif copy[i - 1][j] == "a" then
  47.                                 m[i - 1][j] = fill
  48.                             end
  49.                         end
  50.                     end
  51.                     m[i][j] = fill
  52.                 end
  53.             end
  54.         end
  55.         for i = 1, 17 do
  56.             for j = 1, 51 do
  57.                 if copy[i][j] == tile then
  58.                     copy[i][j] = m[i][j]
  59.                 end
  60.             end
  61.         end
  62.     end
  63.    
  64.     for i = 1, 17 do
  65.       for j = 1, 51 do
  66.           if copy[i][j] == "a" or copy[i][j] == "b" then
  67.               copy[i][j] = fill
  68.             end
  69.         end
  70.     end
  71.    
  72.     return copy
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement