O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — counting matching tiles

To count the matching tiles, follow the ensuing steps:

  1. Add the method CountGems into the game class. The parameters are the first and second object.
    Method CountGems:Int(obj1:ftObject, obj2:ftObject)
    
  2. Define four local INT variables that store the x and y positions of the objects.
    Local x1:Int
    Local y1:Int
    Local x2:Int
    Local y2:Int
    
  3. Now define four INT variables that store the number of gems that were found.
    Local gemCountX1:Int
    Local gemCountY1:Int
    Local gemCountX2:Int
    Local gemCountY2:Int
    
  4. Get the slot positions of both objects.
    x1 = GetSlotX(obj1)
    y1 = GetSlotX(obj1)
    x2 = GetSlotX(obj2)
    y2 = GetSlotY(obj2)
    
  5. Retrieve the gem count of the first object. The position is the one of the second object, as that is where ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required