Jigsaw puzzle ! How do I roll the pieces in random order?

0 favourites
  • 6 posts
From the Asset Store
An amazing and interesting puzzle game for kids!
  • Hello, after many years of gaming experience, I start to work as indie dev in my spare time. For my first game, I wanted something simple.

    I bought an asset for a Jigsaw puzzle that was very basic that I intend to improve and share as a free release.

    From 4 puzzles I created 26 more sceneries from free pictures that I manipulated (add background and so on ...) , Then I changed the hub to make it more appealing and add floating bubbles to pick.

    Everything goes smooth as I learned the basic on Construct and the game was ready in a week.

    But in one moment I realized, the 12 pieces of puzzle always roll in the same order, I mean you can easily remember after 1-2 puzzle where each piece goes.

    Ok it was for 3+ years kids, but it was extremely frustrating and I try hard and didn't find any solution online.

    It was last November, and I quit this project as I thought it was not enough good to put it online to start my second project (still working on it).

    Anyone to break this wall, I will be very thankful :) !!!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Assuming that you are using each frame as a different piece, you can do it like this:

    1. Create an array with dimensions (12, 1, 1)

    2. Give the array a variable "n"

    3. Add the following events on start (or put in a function):

    //First set the values of the array to 0-11, one for each frame.

    Array | for each XYZ element : Array | Set value at (Array.CurX, Array.CurY) to Array.CurX

    //Shuffle the array

    System | For "i" from 0 to array.Width-1 :

    >> Array | Set n to floor(random(Array.Width-loopindex("i")))

    >> Array | Push back Array.At(n,0) on X axis

    >> Array | Delete index n from X axis

    //Assign frames to the pieces using the shuffled array values

    Pieces | Set Animation Frame to Array.At(self.IID)

    To be able to use the IID in this way to assign you shouldn't have any other puzzle pieces in the scene. If you do need additional pieces in the scene for some reason, then instead give the piece sprite a variable e.g. pieceNo, number the pieces 0-11 and use that pieceNo instead of the IID.

    Hope that helps! :-)

  • Hello thanx to your quick answer. I'm going to do my best to follow your indication :D.

  • another idea:

    Repeat 50
     Pick 2 pieces at random
     save values of pieceA (X Y angle ...)
     pieceA = pieceB (X Y angle ...)
     pieceB = values saved
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)