Hi!
I’m a beginner in Corona so i tough it would be a good exercise to make a sliding puzzle.
I managed to create the grid but now I’m stuck in the game mechanics.
[code]display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR
local gridSubdivision = 3
local pieceCount = 0
local lastPiece = (gridSubdivision * gridSubdivision) - 1
local step = 64
local xRoom = 0
local yRoom = 0
local roomNumber = 1
–> Create grid
local puzzle = display.newGroup()
for yp=1,gridSubdivision do
for xp=1,gridSubdivision do
if pieceCount == lastPiece then
local blackPiece = display.newImage( “black.png”, xRoom, yRoom )
local xBlack = xRoom
local yBlack = yRoom
puzzle:insert( blackPiece )
break end
local room = display.newImage( “room” … roomNumber … “.png”, xRoom, yRoom )
room:addEventListener( “touch”, clickHandler )
puzzle:insert( room )
xRoom = xRoom + step
roomNumber = roomNumber + 1
pieceCount = pieceCount + 1
end
xRoom = 0
yRoom = yRoom + step
end
puzzle.xReference = (step * gridSubdivision) / 2
puzzle.yReference = (step * gridSubdivision) / 2
puzzle.x = display.contentWidth / 2
puzzle.y = display.contentHeight / 2[/code]
The specifications :
When you touch a piece, it checks if there is an empty space. If so, it will move to this empty space.
The questions :
- How can i control each pieces independently. In the current situation, I can’t do anything with them.
- When I touch a piece, how to check if there is an empty space and in wich direction?
- Do I need the blackPiece? It is supposed to represent the empty space.
Any suggestion is welcome.
Michael. [import]uid: 25327 topic_id: 7349 reply_id: 307349[/import]