Time for action — creating a gem

This method will create the corresponding image object, set the collision properties for the touch check, and return the object.

  1. Add the method CreateTile to the game class. The parameters are the x and y coordinates of the image object and its tile ID.
    Method CreateTile:ftObject(x:Int, y:Int, tile:Int = -100)
    
  2. Define a local object of the type ftObject.
    Local obj:ftObject
    
  3. If tile is set to -100, determine a random value ranging from 0 to 6.
    If tile = -100 Then tile = Rnd(6)
    
  4. Set the game layer as the default layer.
    eng.SetDefaultLayer(layerGame)
    

    We have six gem images on the sprite sheet. The tile parameter will not only set the object's tag property, but will also set the sprite coordinates.

  5. If tile equals 6, top it to 5.
    If tile = 6 Then tile = 5
    
  6. Depending on the tile parameter, create an image object from the sprite atlas.
    If tile < 4 Then
    obj=eng.CreateImage(atlas,tile*64,64,64,64,x*64,y*64)
    Elseif tile = 4
    obj=eng.CreateImage(atlas,0,128,64,64,x*64,y*64)
    Else
    obj=eng.CreateImage(atlas,64,128,64,64,x*64,y*64)
    Endif
    
  7. Set the object's tag value, the collision radius, and the touch mode to circle. Then, close the method.
    obj.SetTag(tile)
    obj.SetRadius(30)
    obj.SetTouchMode(2)
    Return obj
    End
    

What just happened?

You have created a method that will create a gem sprite for you. If you add more types of gems, then this method has to be modified.

Refilling the tile map

Once gems are removed from the grid, you need to fill it up with new gems. These gems will fall from the top of the grid. The grid will be checked for empty slots (ID = -1) from the bottom to the top, and from left to right, in each row. Once an empty slot is found in a row, the method will either find a gem that can fall down or create a new one.

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

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