Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. _leafs = new Vector<Leaf>;
  2.  
  3. var l:Leaf; // helper Leaf
  4.  
  5. // first, create a Leaf to be the 'root' of all Leafs.
  6. var root:Leaf = new Leaf(0, 0, _sprMap.width, _sprMap.height);
  7. _leafs.push(root);
  8.  
  9. var did_split:Boolean = true;
  10. // we loop through every Leaf in our Vector over and over again, until no more Leafs can be split.
  11. while (did_split)
  12. {
  13. did_split = false;
  14. for each (l in _leafs)
  15. {
  16. if (l.leftChild == null && l.rightChild == null) // if this Leaf is not already split...
  17. {
  18. // if this Leaf is too big, or 75% chance...
  19. if (l.width > MAX_LEAF_SIZE || l.height > MAX_LEAF_SIZE || FlxG.random() > 0.25)
  20. {
  21. if (l.split()) // split the Leaf!
  22. {
  23. // if we did split, push the child Leafs to the Vector so we can loop into them next
  24. _leafs.push(l.leftChild);
  25. _leafs.push(l.rightChild);
  26. did_split = true;
  27. }
  28. }
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement