Page 1 of 1

[CODE] Jigsaw Puzzle Demo

Posted: Fri Jul 13, 2012 3:05 pm
by SusanTheCat
This is a demo that uses Ren'py Cardgame to make a jigsaw puzzle. (http://www.renpy.org/wiki/renpy/Cardgame)

Screen Shots:

This is what the puzzle looks like when you are playing it:
Image

You can drag pieces to have them switch places:
Image

Or click on pieces to have them rotate.
Image

Theory

In Cardgame, you have stacks and cards. Cards are the things you can move around. Stacks are places where you can put cards.

Basically, I made a grid of 12 stacks (4x3) that each contain one card.

Practical

You get your image and slice it into squares. It is important that the pieces are square because you are going to be rotating them.

I used and 800x600 image and cut the pieces into 200x200 px squares using a combination of Gimp, Gimp plugin New Guides Every X Pixels: http://registry.gimp.org/node/13774, and Image>Transform>Guillotine (http://gimp4you.wordpress.com/2008/05/1 ... ce-images/)

The files are named "room-i-j.jpg" where i and j refer to the column and row of the image. (Yeah -- I just realized I got it backwards)

If you want to have a different number of pieces, you just need to play with this section of code:

Code: Select all

        def __init__(self):

            # Constants that let us easily change where the game is
            # located.
            LEFT=100 #half of the size of the piece
            TOP=100
            COL_SPACING = 200 #the size of the piece
            ROW_SPACING = 200
            self.COL_NUM = 4
            self.ROW_NUM = 3
Possible Improvements
- make the code more generic so you can have different puzzles in the same game
- add sound effects

This code is delivered as is. I will answer questions about it, but I will not write your game for you. :)

Susan

Re: [CODE] Jigsaw Puzzle Demo

Posted: Fri Jul 13, 2012 7:43 pm
by Sapphi
Aw, this is neat! Thank you Susan! :)

Re: [CODE] Jigsaw Puzzle Demo

Posted: Thu Apr 25, 2013 4:18 pm
by SusanTheCat
Once again I am leveraging the excellent code of KimiYoriBaka's Drag and Drop Jigsaw Tutorial (http://lemmasoft.renai.us/forums/viewto ... =8&t=12504) and created my own version.
screenshot0001.png
It creates the puzzle pieces using Crop and AlphaMask (http://renpy.org/wiki/renpy/doc/referen ... .AlphaMask) I created 24 (6x4) puzzle pieces and use them as a template.

One thing I did differently is that the puzzle is one long interaction, which means you can't save midway through the puzzle. I haven't decided if I want it to be able to save.

Sorry about the annoying noise. :)

Susan

Re: [CODE] Jigsaw Puzzle Demo

Posted: Thu Apr 25, 2013 10:43 pm
by SilverxBlue
Oh, wow... This is awesome! I've been trying to implement something like this in one of my VNs for a long time now, but I've given up. And now that I've seen something like this, I can try again. Thanks for this! ^__^

Re: [CODE] Jigsaw Puzzle Demo

Posted: Fri May 03, 2013 8:10 pm
by Hellboy
This is very cool! Thanks! :shock:

Hope SusanTheCat doesn’t mind, but I created anti-aliased versions of the jigsaw pieces.
I also did a bevel effect layer to put over the jigsaw image so the pieces appear to have volume.
Of course, you’d better use a clean version for the win image. :D

Re: [CODE] Jigsaw Puzzle Demo

Posted: Sun May 05, 2013 8:40 pm
by SusanTheCat
Hellboy wrote:This is very cool! Thanks! :shock:

Hope SusanTheCat doesn’t mind, but I created anti-aliased versions of the jigsaw pieces.
I also did a bevel effect layer to put over the jigsaw image so the pieces appear to have volume.
Of course, you’d better use a clean version for the win image. :D
Those look freakin' awesome! Thank you.

*\o/*

Susan

Re: [CODE] Jigsaw Puzzle Demo

Posted: Fri Sep 27, 2013 8:38 pm
by FrozenApple66
Do you mind explaining with a bit more detail how to get the code into renpy? Or to even see the code? I'm a bit confused still.

Re: [CODE] Jigsaw Puzzle Demo

Posted: Fri Oct 11, 2013 6:36 pm
by Alex
Thanks a lot, Susan - your code examples are the great help to learn how things work in Ren'Py.
And if you don't mind, I added the ability to break the puzzle to any number of randomly shaped pieces - it uses just 3 stencil images to create all puzzle pieces.


Edit 2019:
Updated the attachment

Re: [CODE] Jigsaw Puzzle Demo

Posted: Sat Oct 12, 2013 12:13 pm
by xela
Alex wrote:Thanks a lot, Susan - your code examples are the great help to learn how things work in Ren'Py.
And if you don't mind, I added the ability to break the puzzle to any number (up to 10x10) of randomly shaped pieces - it uses just 3 stencil images to create all puzzle pieces.
Awesome, thanks for this!

Re: [CODE] Jigsaw Puzzle Demo

Posted: Fri Jun 22, 2018 9:07 pm
by SweetChiel
Thanks a lot, Susan, Hellboy, and Alex! This is exactly what I need for an important part of my game! *cries
I thought there would be no way for Ren'Py to have this kind of drag & drop puzzle, but it managed to surprise me again!

Re: [CODE] Jigsaw Puzzle Demo

Posted: Wed Sep 19, 2018 6:53 am
by hunterhewitt36
I'll work on a non-snapping version, probably need a bunch of IF statements to check the position of each piece and tie these to a timer to constantly check if the puzzle has been solved or maybe have the check routine called each time a piece is moved.

Re: [CODE] Jigsaw Puzzle Demo

Posted: Tue Apr 30, 2019 4:27 am
by Yukari
How can I count the time it took to solve the puzzle?