| 267 | | }, |
|---|
| 268 | | |
|---|
| | 261 | //now actually draw the tiles |
|---|
| | 262 | this.spiralTileLoad(); |
|---|
| | 263 | }, |
|---|
| | 264 | |
|---|
| | 265 | /** |
|---|
| | 266 | * |
|---|
| | 267 | */ |
|---|
| | 268 | spiralTileLoad: function() { |
|---|
| | 269 | var tileQueue = new Array(); |
|---|
| | 270 | |
|---|
| | 271 | var directions = ["right", "down", "left", "up"]; |
|---|
| | 272 | |
|---|
| | 273 | var iRow = 0; |
|---|
| | 274 | var iCell = -1; |
|---|
| | 275 | var direction = directions.indexOf("right"); |
|---|
| | 276 | var directionsTried = 0; |
|---|
| | 277 | |
|---|
| | 278 | while( directionsTried < directions.length) { |
|---|
| | 279 | |
|---|
| | 280 | var testRow = iRow; |
|---|
| | 281 | var testCell = iCell; |
|---|
| | 282 | |
|---|
| | 283 | switch (directions[direction]) { |
|---|
| | 284 | case "right": |
|---|
| | 285 | testCell++; |
|---|
| | 286 | break; |
|---|
| | 287 | case "down": |
|---|
| | 288 | testRow++; |
|---|
| | 289 | break; |
|---|
| | 290 | case "left": |
|---|
| | 291 | testCell--; |
|---|
| | 292 | break; |
|---|
| | 293 | case "up": |
|---|
| | 294 | testRow--; |
|---|
| | 295 | break; |
|---|
| | 296 | } |
|---|
| | 297 | |
|---|
| | 298 | var tile = null; |
|---|
| | 299 | if ((testRow < this.grid.length) && |
|---|
| | 300 | (testCell < this.grid[0].length)) { |
|---|
| | 301 | tile = this.grid[testRow][testCell]; |
|---|
| | 302 | } |
|---|
| | 303 | |
|---|
| | 304 | if ((tile != null) && (!tile.queued)) { |
|---|
| | 305 | tileQueue.unshift(tile); |
|---|
| | 306 | tile.queued = true; |
|---|
| | 307 | directionsTried = 0; |
|---|
| | 308 | iRow = testRow; |
|---|
| | 309 | iCell = testCell; |
|---|
| | 310 | } else { |
|---|
| | 311 | direction = (direction + 1) % 4; |
|---|
| | 312 | directionsTried++; |
|---|
| | 313 | } |
|---|
| | 314 | } |
|---|
| | 315 | |
|---|
| | 316 | // now we go through and draw the tiles in forward order |
|---|
| | 317 | for(var i=0; i < tileQueue.length; i++) { |
|---|
| | 318 | var tile = tileQueue[i] |
|---|
| | 319 | tile.draw(); |
|---|
| | 320 | tile.queued = false; |
|---|
| | 321 | } |
|---|
| | 322 | }, |
|---|