Preparing to swap gems

Not all gems can be swapped. To tell the truth, very few gems can, since a gem can only be swapped with one of its adjacent gems, horizontally or vertically.

The idea: When a gem is selected, and the player clicks on another gem, we must check if the gems are adjacent. If they aren't, then deselect the previously selected gem and select the new one. If they are adjacent, then we are ready to swap them.

The development: Everything runs around the concept of "being adjacent", so we need a function to determine if two gems are adjacent.

Let's express this concept in everyday words: two gems are adjacent if they are on the same column and the first gem is right under or right below the second, or they are on the same row and ...

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.