Pinkishu

Untitled

Jul 6th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. function Maze:_process_neighbor_cells(ox, oy)
  2.     local cellList = { {ox,oy} }
  3.     while #cellList > 0 do
  4.         os.queueEvent("go")
  5.         coroutine.yield()
  6.         local cell = table.remove(cellList,1)
  7.         local x,y = cell[1],cell[2]
  8.         local parent = cell[3]
  9.        
  10.         if not self.cells[y][x].is_visited then
  11.             self.cells[y][x].is_visited = true
  12.  
  13.             local neighbor_cells = self:_shuffle(self:_get_neighbor_cells(x, y))
  14.             if parent then
  15.                 if parent.x > x     then     -- open wall with right neighbor
  16.                     self.cells[y][x].right_wall                              = false
  17.                     self.cells[parent.y][parent.x].left_wall   = false
  18.                 elseif parent.x < x then     -- open wall with left neighbor
  19.                     self.cells[y][x].left_wall                               = false
  20.                     self.cells[parent.y][parent.x].right_wall  = false
  21.                 elseif parent.y > y then     -- open wall with bottom neighbor
  22.                     self.cells[y][x].bottom_wall                             = false
  23.                     self.cells[parent.y][parent.x].top_wall    = false
  24.                 elseif parent.y < y then     -- open wall with top neighbor
  25.                     self.cells[y][x].top_wall                                = false
  26.                     self.cells[parent.y][parent.x].bottom_wall = false
  27.                 end
  28.              
  29.             end
  30.             for index, neighbor_cell in ipairs(neighbor_cells) do
  31.                 if self.cells[neighbor_cell.y][neighbor_cell.x].is_visited == false then
  32.                     table.insert(cellList,1,{neighbor_cell.x,neighbor_cell.y,{x=x,y=y}})
  33.                 end
  34.                 --self:_process_neighbor_cells(neighbor_cell.x, neighbor_cell.y)
  35.             end
  36.         end
  37.     end
  38.  
  39.     return
  40. end
Advertisement
Add Comment
Please, Sign In to add comment