hi all. i'm looking for some example on puzzle games which "detect"
(show the user) that the pieces are arranged correct. those i know
are "simple" drag and drop together ones with do not detect that the
pieces are arranged correct and fit. any examples or ideas on how
to "detect" that (when having different puzzle piece forms)? thanks:
lars

There are various levels of this. One (generally for the simplest puzzles for small children) locks the pieces to their exact space on the board. That's pretty easy to do: assuming you know where each piece belongs, when the mouse is released you simply calculate its distance from the target position and lock if it's below a certain threshold.

The next level is where you link pieces to each other rather than to the board. Actually, this isn't much harder to do: you store the pieces' correct x and y positions, then when a piece is dropped, you look for the relative positions of its neighbours, and check how close they are to correct (eg: you know that the right-neighbour must be at a relative position of (w,0), so if it's currently at (w+1,2) you decide that's close enough and lock it in place.

The next level, for an irregular grid, is to store for each piece a list of the neighbours it can link to, and continue as the previous example.

Finally, you can allow rotation of pieces. This is exactly the same as before, but you also have to check that the pieces are at the correct relative orientation (in particular, it affects the calculation of the 'relative position' of the neighbour pieces.

Clear? I can give you some code, but an explanation is generally more useful...

Danny
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to