Game Development Reference
In-Depth Information
merge = true;
finalGroup = m_group.merge(finalGroup,
mergeGroups[i]);
}
if ( merge ) {
return finalGroup;
}
else {
// no new group was formed
return null;
}
}
The crucial logic is in the _checkMatch method, which checks if there are any correct
pieces around it that are close enough. If so, the group is added to the returned array.
We then actually merge the groups into one group and return it. If there were no
groups to merge, we return null .
In each direction, we calculate the difference—that is, how close the correct piece is
to this piece. If it is within the tolerance ( MATCH_ALLOWANCE ) that is seven pixels, we
move the group exactly to the pixel so that they appear to be attached.
The following listing shows the listing for the _checkMatch method that deals with
the correct top piece:
public function _checkMatch(merge:Array):Boolean {
var ret:Boolean = false;
var diff:Point = null;
if ( !m_topMatch && (m_top != null) ) {
diff = _getDiff(DIR_TOP);
if ( Math.abs(diff.x) < MATCH_ALLOWANCE &&
Math.abs(diff.y) < MATCH_ALLOWANCE ) {
ret = true;
m_topMatch = true;
m_top.getGroup().move(diff.x, diff.y, null);
_sendPieceMatch(DIR_TOP);
merge.push(m_top.getGroup());
}
}…
The exact same logic is applied for the other three directions.
 
Search WWH ::




Custom Search