Adding new gems

No matter if you make gems fall to fill empty places, or leave them as they are, when you remove some gems from the game field, you will need to replace them with new ones.

The idea: Once the gems have been removed and empty spaces have been filled with gems from above (if any), we must scan jewels array and create new gems wherever we find a -1.

The development: I told you this was easy, and this time we just need a couple of for loops. Obviously new gems will be created at the very end of the gems removal process, so we'll call the function to replace gems at the very end of removeGems function.

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

And replaceGems function is very easy as it just looks for ...

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.