Advertisement
billysback

Square checking thingy mk2

Oct 19th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.79 KB | None | 0 0
  1. local function checkCellSquare(x, y)
  2.     local n = 0
  3.     for xo=-1,1,2 do
  4.         for yo=-1,1,2 do
  5.             if getCell(x+xo, y) == 1 then n = n + 1 end
  6.             if getCell(x, y+yo) == 1 then n = n + 1 end
  7.             if getCell(x+xo, y+yo) == 1 then n = n + 1 end
  8.         end
  9.     end
  10.     return n
  11. end
  12.  
  13. local function checkCell(x,y)
  14.    
  15.     local coords = { { {-1, 0}, {-1, -1}, {0, -1}}, { {-1, 0}, {-1, 1}, {0, 1} }, { {0, 1}, {1, 1}, {1, 0} }, { {1, 0}, {1, -1}, {0, -1} } }
  16.     local ok = false
  17.     if getCell(x, y) == 1 then
  18.         for i=1,#coords do
  19.             local n = 0
  20.             local coord = coords[i]
  21.             for j=1,#coord do
  22.                 local co = coord[j]
  23.                 --n = n + 1
  24.                 if getCell(co[1]+x, co[2]+y) == 1 then n = n + 1 end
  25.             end
  26.             if n == #coord then
  27.                 ok = true
  28.             end
  29.         end
  30.     end
  31.     if ok then ok = (checkCellSquare(x,y) == 3) end
  32.     return ok
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement