Game Development Reference
In-Depth Information
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 play-
er. 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:
1. 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()
g:setType( self.grid[c][r] )
g:setPosition ( c * (constants.TILE_SIZE +
constants.GRID_SPACE),
r * (constants.TILE_SIZE +
constants.GRID_SPACE))
self.gemsContainer:addChild(g)
self.gridGemsColumnMap[c][r] = g
table.insert(self.allGems, g)
end
end
self.gridAnimations:animateIntro()
end
Search WWH ::




Custom Search