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 — 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, ...

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