How do I compare different instances positions ?

Get help using Construct 2

Post » Sun Apr 19, 2015 3:13 pm

Hello,
First of all I apologize for my bad english because it is not my native language.

I am doing a board game which is aimed to create shapes with some pawns in the way of "Connect Four".
For example I want to detect when 5 tokens are aligned (like that : imagizer.imageshack.us/a/img910/9062/VS7cEE.jpg).
My problem : I don't know how to compare the positions of multiple instances of a same object. I tried to use families but that was without any success..

Thank you for your help ! :)


PS : Perhaps my question has already been asked on the forum but I did not find an appropriate answer. Anyway I am sorry if the subject has already been posted.
B
3
Posts: 2
Reputation: 179

Post » Sun Apr 19, 2015 5:09 pm

You could make a "Check system" that would go through all pawns. Since you already know the position (Depending on how you made it of course), you should be able to store the values in an array as variables for each pawn, whatever you prefer.

Board and there indexes
Code: Select all
(0,0), (1,0), (2,0)
(0,1), (1,1), (2,1)
(0,2), (1,2), (2,2)


So if you place a pawn on (1,1) you add that to a list.

List:
(1,1)

Then you use this to check surrounding indexes. So if there is a pawn on 0,0 you add that one as well.

List
(1,1)
(0,0)

And you keep doing that until there are no more pawns to be found surrounding the index you are checking. And if the list have 5 elements you know that there are 5 pawns.

However that will ofc not account for them being on a straight line etc. so you will have to make sure that is taken into account as well. And also you have to make sure that those pawns already on the list is not check vs again.

But in theory I think that should solve it.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Sun Apr 19, 2015 7:19 pm

Use flood-fill with 8 direction detection as proposed by R0J0:
http://dl.dropbox.com/u/5426011/example ... chain.capx

I use his method for columns puzzle prototype.
ImageImage
B
105
S
46
G
23
Posts: 778
Reputation: 22,226

Post » Mon Apr 20, 2015 1:23 pm

Thanks a lot for your super fast answers ! I am going to try your methods as soon as possible and see if I achieve to fix my problem.

By the way here is an extract of what I tried to do first, just in case there would be a way to make it work with that kind of system by picking the right pawns (even if I think that way won't work..) : imageshack.com/a/img901/8311/4l3GGc.jpg
On that screenshot sBlackPawn is a sprite and fBlacksPawns is a Family, the global number is just here to see if something is detected.
B
3
Posts: 2
Reputation: 179


Return to How do I....?

Who is online

Users browsing this forum: unicornspitfire and 66 guests