Game Development Reference
In-Depth Information
Note that we start with the piece's group and then call
checkMatch
. The check match
will return a merged group if there was a merge with another group. We keep a
reference to the merged group in finalGroup. We then call the
checkMatch
with the
last merged group again to see if there is another group to merge with. We do this
until there are no more groups to be merged.
Let's see what happens in the
checkMatch
method inside the group class:
public function checkMatch():Group {
var ret:Group = null;
var i:int=0;
var len:int = m_pieces.length;
// go through each piece and check if
// piece was merged with a piece from
// another group.
for ( i=0; i<len; i++ ) {
var p:PieceSprite = m_pieces[i];
var g:Group = p.checkMatch();
if ( g != null )
ret = g;
}
return ret;
}
The method goes though each piece in the group and calls the
checkMatch
method
on the piece. The
checkMatch
will return the merged group if the groups merge.
Let's follow the
checkMatch
on the
PieceSprite
class:
public function checkMatch():Group {
var mergeGroups:Array = new Array();
// returns all the groups that were
// merged when a group was moved
_checkMatch(mergeGroups)
var merge:Boolean = false;
var finalGroup:Group = m_group;
var i:int;
for (i=0; i<mergeGroups.length; i++ ) {
var g:Group = mergeGroups[i];
// probably already merged
if ( g.getSize() == 0 )
continue;
// avoid merging with self or
// final merged group
if ( finalGroup == g )
continue;