Making gems fall

Once each gem is removed, we have to adjust the game field making the above gems fall down to fill empty spaces.

This is the last hard to develop feature you will encounter in this chapter. After managing with falling gems, making the rest of the game will be quite easy.

The idea: Starting from the bottom-most row, we must look for empty spaces. Once an empty space is found, all the gems (if any) in the same column above the empty space should fall down to fill the empty space.

The development: Obviously the need of adjusting the game field occurs only after some gems have been removed.

So the entire routine will be called at the end of removeGems function:

private function removeGems(row:uint,col:uint):void { ... adjustGems(); ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.