Time for action — clearing the tile map

The following method will search through the tile map. If a slot is filled with the value 99 that means the corresponding tile needs to be deleted.

  1. Insert a method header named ClearGems into the game class.
    Method ClearGems:Int()
    
  2. Start two FOR loops, one for the rows and one for the columns.
    For Local r:Int = 1 To rows
    For Local c:Int = 1 To columns
    
  3. Check if the tile map contains the value 99.
    If tileMap[c-1][r-1] = 99 Then
    
  4. If yes, initialize the slot.
    tileMap[c-1][r-1] = -1
    
  5. Next, perform a touch check. The current number of columns and rows has each to be multiplied by 64 (the image width). The ID is set to 99.
    layerGame.TouchCheck(c*64.0, r*64.0, 99)
    

    I'm sure you wondering why we use a touch check. Later, in the engine class, we will check inside the OnObjectTouch method for this ID and then remove the object.

  6. Close the IF check, both FOR loops, and the method.
    Endif
    Next
    Next
    Return 0
    End
    

What just happened?

You have created a method that will look through the tile map and initialize all slots that need to be deleted and also will take care that the corresponding gem image object will be removed later.

Counting matching tiles

The next method will be used when two tiles are selected and you need to find out if they can be switched. For this, we need to know how many tiles are the same when both tiles are in their new positions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.196.172