Time for action — refilling the tile map

  1. Create a new method called FillTiles inside the game class.
    Method FillTiles:Int()
    
  2. Add two local variables with the type BOOL. They will be used to determine if a row was filled.
    Local filled:Bool = False
    Local filled2:Bool = False
    
  3. Start two FOR loops for the rows and the columns.
    For Local r:Int = rows To 1 Step -1
    For Local c:Int = columns To 1 Step -1
    
  4. Set filled2 to False and check if the tile map is in the initial position (= -1).
    filled2 = False
    If tileMap[c-1][r-1] = -1 Then
    
  5. If yes, then check if the current row is not the top one.
    If r > 1 Then
    
  6. If yes, start another FOR loop going backwards to create a temporary row ranging from the current row minus one to one (the top row).
    For Local r2:Int = r-1 To 1 Step -1
    
  7. Get the current object with a new method of the fantomEngine, called GetObjAt.
    Local obj:ftObject = layerGame.GetObjAt(c*64, r2*64)
    
  8. If an object was found, check if it is not in transition.
    If obj <> Null And obj.GetTransitionCount()=0 Then
    
  9. If it isn't, set filled with True, as we've now found a gem that needs to be moved to our empty slot.
    filled = True
    
  10. Initialize the corresponding slot tile ID of the gem that was found.
    g.SetSlotTile(g.GetSlotX(obj), g.GetSlotY(obj),-1)
    
  11. Create a position transition with the current column and row as target. The transition ID is set to 99.
    obj.CreateTransPos(c*64.0,r*64.0,300,False, 99)
    
  12. Set filled2 to True and exit the method. Close the IF check and the FOR loop.
    filled2 = True
    Exit
    Endif
    Next
    
  13. If filled2 is False, then no gem was found above. Set filled to True.
    If filled2 = False Then
    filled = True
    
  14. Add a new gem tile with the method CreateTile.
    Local newObj:=CreateTile(x,0)
    
  15. Create a position transition for this new tile, and then close the IF check.
    newObj.CreateTransPos(c*64.0,r*64.0,300,False, 99)
    Endif
    
  16. If we are actually in row 1, then set filled to True and directly add a new gem tile.
    Else
    filled = True
    Local newObj:=CreateTile(c,0)
    
  17. Again, create a position transition for this new gem.
    newObj.CreateTransPos(c*64.0,1*64.0,300,False,99)
    
  18. Close the last two IF checks and the FOR loop.
    Endif
    Endif
    Next
    
  19. If filled is set to True, then exit the method.
    If filled = True Then Exit
    
  20. Close the top FOR loop and close the method.
    Next
    Return 0
    End
    

What just happened?

Wow, what a method! But it will do the dirty job of iterating through the tile map and filling it with new tiles.

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

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