Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _leafs = new Vector<Leaf>;
- var l:Leaf; // helper Leaf
- // first, create a Leaf to be the 'root' of all Leafs.
- var root:Leaf = new Leaf(0, 0, _sprMap.width, _sprMap.height);
- _leafs.push(root);
- var did_split:Boolean = true;
- // we loop through every Leaf in our Vector over and over again, until no more Leafs can be split.
- while (did_split)
- {
- did_split = false;
- for each (l in _leafs)
- {
- if (l.leftChild == null && l.rightChild == null) // if this Leaf is not already split...
- {
- // if this Leaf is too big, or 75% chance...
- if (l.width > MAX_LEAF_SIZE || l.height > MAX_LEAF_SIZE || FlxG.random() > 0.25)
- {
- if (l.split()) // split the Leaf!
- {
- // if we did split, push the child Leafs to the Vector so we can loop into them next
- _leafs.push(l.leftChild);
- _leafs.push(l.rightChild);
- did_split = true;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement