Problem : 15 game

Get help using Construct 2

Post » Fri Nov 18, 2011 5:40 pm

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 :
(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 ?
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Post » Fri Nov 18, 2011 6:16 pm

I thought that construct2 does not work with .capx files...
B
4
S
1
G
1
Posts: 36
Reputation: 949

Post » Fri Nov 18, 2011 6:31 pm

@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.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Fri Nov 18, 2011 7:30 pm

@Kyatric: thanks, many interesting information!
B
4
S
1
G
1
Posts: 36
Reputation: 949

Post » Fri Nov 18, 2011 8:38 pm

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 array.at(X,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.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Fri Nov 18, 2011 8:56 pm

@Kyatric : it's my fault, I realized the plugin used is the old version (http://dl.dropbox.com/u/31151399/Construct2/Plugins/randomArray_old.zip) 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 ?)
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Post » Fri Nov 18, 2011 10:30 pm

I'm french from France indeed.
I figured you might be too when I saw the name of your project
I'll have a look at the capx with the correct plugin later.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Fri Nov 18, 2011 10:41 pm

@Kyatric : yes, same disease as yours ;)
Thanks for the help.
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Post » Sat Nov 19, 2011 8:39 pm

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:
http://dl.dropbox.com/u/5426011/examples%208/9tile.capx
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Sat Nov 19, 2011 9:37 pm

@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.
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Next

Return to How do I....?

Who is online

Users browsing this forum: Radulepy and 5 guests