Time for action — refilling the tile map
- Create a new method called
FillTiles
inside the game
class. - Add two local variables with the type BOOL. They will be used to determine if a row was filled.
- Start two FOR loops for the rows and the columns.
- Set
filled2
to False
and check if the tile map is in the initial position (= -1)
. - If yes, then check if the current row is not the top one.
- 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).
- Get the current object with a new method of the fantomEngine, called
GetObjAt
. - If an object was found, check if it is not in transition.
- If it isn't, set
filled
with True
, as we've now found a gem that needs to be moved to our empty slot. - Initialize the corresponding slot tile ID of the gem that was found.
- Create a position transition with the current column and row as target. The transition ID is set to
99
. - Set
filled2
to True
and exit the method. Close the IF check and the FOR loop. - If
filled2
is False
, then no gem was found above. Set filled
to True
. - Add a new gem tile with the method
CreateTile
. - Create a position transition for this new tile, and then close the IF check.
- If we are actually in row
1
, then set filled
to True
and directly add a new gem tile. - Again, create a position transition for this new gem.
- Close the last two IF checks and the FOR loop.
- If
filled
is set to True
, then exit the method. - Close the top FOR loop and close the method.
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.