How to make a puzzle game?

100062114100062114 Member Posts: 13
edited July 2014 in Help Wanted

I try to code a game which is like a puzzle.
The computer generate a puzzle, for example, a L-type.
The user can drag the puzzle to a grid plane, the puzzle can be automatically put in the grid plane exactly.
How do I make gamesalad do these things?

Comments

  • gazzcoolgazzcool Member Posts: 7
    edited July 2014

    Okay so firstly you want to make your L shape object (I will just call it actor 1) to be able to be clicked and dragged. Here's what I would do:

    Double click on actor 1 and create a new rule:

    When all conditions are valid:

    • Actor receives event mouse button is down
    • Actor receives event mouse position is up

    Constrain attribute:

    • self.Position.X To: game.Mouse.Position.X

    Constrain attribute:

    • self.Position.Y To: game.Mouse.Position.Y

    Now you should be able to drag and drop actor 1 around, while in preview mode.

    For the 'snapping into place' feature it's a little more complicated. First you will need your 'grid' (I will just call it actor 2) so create that. You will also need to create to attributes, so in your inspector, go to Game ->Attributes -> and click the '+' symbol at the bottom. Create a new integer called something like 'X-position' and another called 'Y-position'. Now we need to set them to whatever position actor 2 is at (double click on actor 2 in the camera window and click the little symbol next to 'Position' to find this). If you are planning on moving actor 2 around, I would suggest constraining these attributes to the position of actor 2. To do this, double click on actor 2 in the inspector and add two attributes:

    Constrain attribute:

    • game.X-Position To: self.Position.X

    Constrain attribute:

    • game.Y-position To: self.Position.Y

    Okay now we need to create a new rule in Actor 1, in order to snap it into place. Obviously you can replace the number 20 with any number you like, depending on how close or far you need to be before it will snap into place:

    When all conditions are valid:

    • Actor receives event: mouse button is up
    • Attribute self.Position.X > game.X-position-20
    • Attribute self.Position.X < game.X-position+20
    • Attribute self.Position.Y > game.Y-position-20
    • Attribute self.Position.Y < game.Y-position+20

    Change Attribute:

    • self.Position.X To: game.X-position

    Change Attribute:

    • self.Position.Y To: game.Y-position

    Of course this is just assuming you only want to snap it to one place, as opposed to anywhere in the grid. But hopefully this will give you a good starting point. Let me know if you have any trouble.

Sign In or Register to comment.