Shadowspaz

findArea.as

Feb 22nd, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function findArea(blockType:int = 10):void
  2. {
  3.   var largest:int = 0;
  4.   var current:int = 0;
  5.   var root:int = 0;
  6.   var source:int = 0;
  7.   var tempWidth:int = 0;
  8.   for (var i:int = 0; source < worldBuildArray.length; i++) { //Finds largest cluster of matching tiles, vertically
  9.     if (((i % worldWidth) == 0 ? 20 : i % worldWidth) - (source % worldWidth) == tempWidth && tempWidth != 0) i +=
  10.     (worldWidth - tempWidth); //Shifts to next row of temp rect.
  11.     if (i > worldBuildArray.length) { // Delimits at bottom of map
  12.       i = source+1;
  13.       tempWidth = 0;
  14.       if (current > largest) largest = current;
  15.       current = 0;
  16.     }
  17.     if (current == 0) source = i;
  18.     if (worldBuildArray[i] == blockType && (tempWidth != 0 || Math.floor(source/worldWidth) ==
  19.     Math.floor(i/worldWidth))) { //Main block check/delimiter at edge of map.
  20.         current++; 
  21.         if (current > largest) {
  22.           largest = current;
  23.           root = source;
  24.         }
  25.       } else {
  26.         if (tempWidth == 0 && source != i) { // When detect collision, set tempWidth and shift row
  27.           tempWidth = current; 
  28.           i += (worldWidth - tempWidth);
  29.         } else { // If collision within temp rect, reset to 'source.'
  30.           tempWidth = 0;
  31.           current = 0;
  32.           i = source;
  33.         }
  34.       }
  35.     //trace(source + " / " + i);
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment