Puzzle/Jigsaw script?
by Andrea Farid Marsili · in iTorque 2D · 05/28/2011 (12:11 pm) · 6 replies
Can you give me some advice about coding a puzzle?
#2
05/29/2011 (12:27 am)
I already think about this way but with a single point is almost impossible to finish the puzzle.
#3
I am also doing a puzzle game. There are many ways you can do it, the one I am doing is to define a C++ 2D array and some logic that makes objects in each grid position interact with each other.
You can find an example of this here
www.garagegames.com/community/resources/view/21023
05/29/2011 (2:31 pm)
@AndreaI am also doing a puzzle game. There are many ways you can do it, the one I am doing is to define a C++ 2D array and some logic that makes objects in each grid position interact with each other.
You can find an example of this here
www.garagegames.com/community/resources/view/21023
#4
1. Chop your image up into pieces - have two pieces for each piece of the puzzle, one piece has the picture - the other is invisible. You can clone the picture piece and set visible = false. Both pieces have the same id.
2. Lay out the invisible pieces on the screen in the correct place for the puzzle.
3. Randomly scramble the picture pieces.
Player drags the pieces around and you check for collisions between picture and invisible. When the two ids are a match (src.id == dst.id) then the player has a piece in the right place and you lock it into place. You'll need to check that the piece is the right way up - you can check if the piece is rotated etc.
This was you don't have to track screen coordinates - you just need an algorithm for laying the (invisible) puzzle out.
05/29/2011 (4:44 pm)
Here's another way of doing it ...1. Chop your image up into pieces - have two pieces for each piece of the puzzle, one piece has the picture - the other is invisible. You can clone the picture piece and set visible = false. Both pieces have the same id.
2. Lay out the invisible pieces on the screen in the correct place for the puzzle.
3. Randomly scramble the picture pieces.
Player drags the pieces around and you check for collisions between picture and invisible. When the two ids are a match (src.id == dst.id) then the player has a piece in the right place and you lock it into place. You'll need to check that the piece is the right way up - you can check if the piece is rotated etc.
This was you don't have to track screen coordinates - you just need an algorithm for laying the (invisible) puzzle out.
#5
An example of a game that does puzzles like this is lego harry potter for the iphone. As long as you drag the puzzle piece to the correct location within so many pixels it will lock it into the correct place. Works really well for them.
05/31/2011 (6:24 am)
@Andrea to avoid the single point problem you can give the puzzle piece a range to fit in. So say that the upper left pixel's exact location is (10,10) for where it should be. You can say that if it is anywhere from(5-15,5-15) then snap it to the correct location and lock it in. That way as long as they get it close enough to the correct spot it will lock it in.An example of a game that does puzzles like this is lego harry potter for the iphone. As long as you drag the puzzle piece to the correct location within so many pixels it will lock it into the correct place. Works really well for them.
#6
Make the actor movable using touch. OnTouchRelease calculate the distance between a point (or another actor) and my puzzle piece. After X sec and if distance is less than Y change actor position to the point position.
06/02/2011 (2:14 am)
I had an idea:Make the actor movable using touch. OnTouchRelease calculate the distance between a point (or another actor) and my puzzle piece. After X sec and if distance is less than Y change actor position to the point position.
Torque Owner Juntaou