Problem : 15 game

0 favourites
  • 14 posts
From the Asset Store
A pack contains high quality game backgrounds for 2D video games. With 15 distinct themes
  • Here is the capx of a Fifteen game I made (the tiles are a bit small, but they are going to be replaced by a larger image at the end).

    Fifteen Game capx

    And here's the screenshot : <img src="" border="0">

    (By the way, I'm using the Random Array plugin)

    As you can see, the logic I tried to make to switch between tiles is a bit strange, since at the time I didn't want to use a second array to store the game. In fact, I store the properties of the tile I clicked on, I move the mouse with the left button pressed, and I store the properties of the tile I lifted my finger on. If the two are a tile next to the empty spot, the move is "valid". With that, I have the problem that I can jump across the board, if the destination spot is the empy spot...

    Right now, I have two more problems : the first one (which is minor and doesn't bother me if I can't do it another way) is that I want to slide the tile with the mouse, without going outside the grid, and without allowing collision without another Sprite (just letting the player go to the empty spot with his selected tile). For the moment, there is no "sliding" movement. I validate the tile switch after the gesture, and there is nothing "dynamic". Anyway, it's just a cosmetic problem so it's not the biggest one.

    The other problem is that I want a "victory" condition. For that, I need to know if the tiles are in the right order. Since I don't use an array (and using an array seems difficult for me in that context of "sliding" tiles), I need to find a quick trick to do that.

    One of my idea was to use an invisible "growing bar" on the left of the game, which count the tile it intersect at each tick, and if the order of those tiles is the right one (i.e. "1", "2", "3", and "4"), then that row is good ! Repeat that for the 4 rows, and we have a victory condition...

    In the end, I think that all my code is overly complicated and that the victory condition can be made simpler. Does anybody have an idea ?

  • I thought that construct2 does not work with .capx files...

  • JohnJ: you might want to check out this tutorial treating the differences between C2 and CC as well as documentation to check out for the one, the other or even both.

  • Kyatric: thanks, many interesting information!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So concerning the problem, I can't open the capx, even after having installed the plugin version from Joe7's topic.

    Have you updated the plugin you are using or could it be some old version, that would explain the incompatibility ?

    An array could help somehow. Two dimensions.

    Talking from your picture,

    x: 0, y:0, value null

    x: 1, y:0, value 6

    x: 2, y:0, value 3

    x: 3, y:0, value 9

    Etc... all the way to

    x: 0, y:3, value 16

    x: 1, y:3, value 5

    x: 2, y:3, value 14

    x: 3, y:3, value 11

    Set a variable VC = 0

    Set a variable 2Comp = 0

    For each Tiles, store tile.index (or the name of the value they are displaying) to the correct X, Y in the array.

    Set VC to 1 and run two loops (one for Y and the other for X).

    Check that the value of,Y) matches 2Comp and increment it each step. (the value of 2Comp would then be 0, then 1, 2 etc...)

    Making a while loop in events if you want. As long as the values match, you do nothing.

    The moment the comparison is false, you could set VC to 0.

    After the looping is done, check VC. If it is 1, then you have ordered all the tiles as expected.

    If it's 0, victory is not there.

    You could facilitate things by keeping the X and Y of our virtual grid as instance variable of the tiles. It will make it easy/quicker to store the values in the array.

    That's an implementation I guess.

  • Kyatric : it's my fault, I realized the plugin used is the old version ( of RandomArray. I remember I kept that one, because I can use the "CurValue", which is missing from the new version).

    (Something completely unrelated. I saw that you are in France, but I don't remember where I saw that, are you french yourself ?)

  • I'm french from France indeed.

    I figured you might be too when I saw the name of your project <img src="smileys/smiley1.gif" border="0" align="middle" />

    I'll have a look at the capx with the correct plugin later.

  • Kyatric : yes, same disease as yours ;)

    Thanks for the help.

  • I haven't opened your capx but here's an idea to do the sliding of the tiles.

    1. When you start dragging store the start position, and the x,y distances to the empty space.

    For example if the tiles are spaced every 100 pixels:

    empty above: x,y distances= 0, -100

    empty below: x,y distances= 0, 100

    empty left: x,y distances= -100, 0

    empty right: x,y distances= 100, 0

    2. Then while dragging contain the tile's position from the start position to the x,y distances.

    ex for x:

    start_x + clamp( Mouse.X - start_x, min(0, x_distance), max(0,x_distance))

    3. On the end of the drag just snap the tile to the grid.

    Example capx:

  • R0J0hound : you are killing me :). I have two problem, and in the same day, you score on those two, easily and with efficiency ! Thanks a lot.

  • Sorry to resurrect this topic, but the example here is what I intend to study. I just want to know how to make the pieces slide into the empty spot when clicked. You can use the bounce effect together, right? Any explication will be help. Thanks

  • R0J0hound:

    That looks real good. One question:

    I'm trying to resize the sprites and I can do it manually but I have a distance between the sprites if I do that.

    How can I move smaller sprites next to each other? Does that make sense?

  • hopr37

    Other than changing the sprite sizes from 133 you'll also need to change all the 133's to the new size. That and reposition the sprites in the editor to be positioned on a grid size of the same value.

  • I got it. Finally figured something out on my own. Thanks for the reply

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)