Pinkishu

Untitled

Jul 6th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | None | 0 0
  1. local vecMods = { {0,-1}, { 1,0}, { 0,1}, {-1,0} }
  2. local dir = 2
  3. local out = 0
  4. local currentLoc = {0,0}
  5.  
  6. function processField()
  7.   print("Processed!")
  8. end
  9.  
  10. function moveOn()
  11.   currentLoc[1] = currentLoc[1] + vecMods[dir][1]
  12.   currentLoc[2] = currentLoc[2] + vecMods[dir][2]
  13. end
  14.  
  15. function isEdge(loc)
  16.   local edgeLocs = {
  17.                       { -out, -out },
  18.                       { out, -out },
  19.                       { -out, out },
  20.                       { out, out }
  21.                    }
  22.   for _,v in pairs( edgeLocs ) do
  23.     if v[1] == loc[1] and v[2] == loc[2] then return true end
  24.   end
  25.   return false
  26. end
  27.  
  28. function moveOut()
  29.   dir = 2
  30.   moveOn()
  31.   out = out + 1
  32. end
  33.  
  34.  
  35.  
  36. processField()
  37. while true do
  38.   moveOut()
  39.   startLoc = {}
  40.   startLoc.x = currentLoc[1]
  41.   startLoc.y = currentLoc[2]
  42.   processField()
  43.   dir = 3
  44.   moveOn()
  45.   processField()
  46.   while (currentLoc[1] ~= startLoc.x or currentLoc[2] ~= startLoc.y) do
  47.     if isEdge(currentLoc) then dir = dir % 4 + 1 end
  48.     moveOn()
  49.     processField()
  50.   end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment