Time for action – building the gems
There are basically two types of match-three games, those in which the selection of matches takes place automatically and those in which the matches are selected by the player. Candy Crush is a good example of the former, and Diamond Dash of the latter. When building the first type of game, you must add extra logic to ensure you start the game with a grid that contains no matches. This is what we'll do now:
- We start with the
buildGrid
method:function GameScene:buildGrid () math.randomseed(os.clock()) self.enabled = false local g for c = 1, constants.GRID_SIZE_X do self.grid[c] = {} self.gridGemsColumnMap[c] = {} for r = 1, constants.GRID_SIZE_Y do if (c < 3) then self.grid[c][r] = constants.TYPES[ self:getVerticalUnique(c,r) ] else self.grid[c][r] = constants.TYPES[ self:getVerticalHorizontalUnique(c,r) ] end g = Gem:create...