Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function findArea(blockType:int = 10):void
- {
- var largest:int = 0;
- var current:int = 0;
- var root:int = 0;
- var source:int = 0;
- var tempWidth:int = 0;
- for (var i:int = 0; source < worldBuildArray.length; i++) { //Finds largest cluster of matching tiles, vertically
- if (((i % worldWidth) == 0 ? 20 : i % worldWidth) - (source % worldWidth) == tempWidth && tempWidth != 0) i +=
- (worldWidth - tempWidth); //Shifts to next row of temp rect.
- if (i > worldBuildArray.length) { // Delimits at bottom of map
- i = source+1;
- tempWidth = 0;
- if (current > largest) largest = current;
- current = 0;
- }
- if (current == 0) source = i;
- if (worldBuildArray[i] == blockType && (tempWidth != 0 || Math.floor(source/worldWidth) ==
- Math.floor(i/worldWidth))) { //Main block check/delimiter at edge of map.
- current++;
- if (current > largest) {
- largest = current;
- root = source;
- }
- } else {
- if (tempWidth == 0 && source != i) { // When detect collision, set tempWidth and shift row
- tempWidth = current;
- i += (worldWidth - tempWidth);
- } else { // If collision within temp rect, reset to 'source.'
- tempWidth = 0;
- current = 0;
- i = source;
- }
- }
- //trace(source + " / " + i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment