Personally i would not use the physics engine. You do not need it.
You really only need a two-dimensional table to hold the tile info, and you can use two for loops to read the data.
Your table would look like this:
myTiles = {{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0}}
That represents your grid of tiles. Generally a match-3 game relies on colors, so you could use an integer to hold color values. i.e: red = 1, blue = 2, yellow = 3, and so forth.
The functions to build the grid and to check the grid for matches would utilize a nested for loop, like this:
local function buildGrid()
for i = 1, #myTiles, 1 do
for j = 1, #myTiles[i], 1 do
local randomColor = math.random(1,7)
local myTile = display.newImage("images/block"..randomColor..".png")
myTile.myColor = randomColor
myTile.myName = "t\_"..i.."\_"..j
myTile.x = (j - 1) \* tileWidth -- set tileWidth at the top of the file
myTile.y = (i - 1) \* tileHeight -- set tileHeight at the top of the file
myTile:addEventListener("touch", touchTile)
myTiles[i][j] = randomColor
end
end
end
That is very basic code to lay out a grid of randomly colored tiles. The nested for loop will “walk” over each block in the grid. In this setup, the “i” loop represents the rows, and the “j” loop represents the columns of the grid.
The above code will lay out the grid. You will need to devise similar functions to check for matches, and drop new tiles.
A match-3 game needs these functions:
- Build the map
- Player swaps tile
- Check for matches
- Delete matches (or better yet, move them to the top)
- Drop the tiles
- Repeat step 3, if no matches found go to step 7.
- Return control to the player
Hope this gets you started!
Joe
[import]uid: 8444 topic_id: 4619 reply_id: 14592[/import]