In my case the rotation of the parts doesn’t matter, but how can I detect for each part if there is a connection with the starting point?
All parts have an id, depending on which position they are in.
Checking next higher and lower id does not work if there is more than one row.
Checking if points from one part are in another part does not work if they are instances of the same object, same with collision.
Many different game mechanics need to check if connections exist. If it’s candy crush or a street in an RTS, but I could never find a solution.
The main loop would be to constantly look for the square /location / sprite / the variable, whatever we call it, that’s need to be checked. No need to check them all if there’s only 1 variable that is connected to the water.
So first before the loop starts, set the 50 path.n.tocheck to false. Turn the path.startingpoint.tocheck variable to true, where the water comes from.
Also turn path.startingpoint.connected to true
Set n to 1
Then the main loop checking n, adding n at the end of the loop, and if n=51, set n to 1.
Tje condition of the loop is to go on till there is no “to check” variable true anymore. (for that you’ll need a counting variable that count how many times the loop run into a tocheck that is true. When this counter is 0, stop the loop)
Inside the loop:
if path.n.tocheck is true:
higher square:
- if path.(n-50)connected is false
- if direction.up.[path.n.typeofsquare] =true
- and if direction.down.[path.[n-50] .typeofsquare] =true
- - - - - > then set path[n-50]tocheck to true
- - - - - → and set path[n-50]connected to true
left square… And so on
So your main variable would be, for each square n :
Path.n.tocheck
Path.n.connected
Path.n.typeofdquare
And also:
Direction.up.typeofsquare
Direction.left.typefosquare
Direction.right.typefosquare
Direction.down.typefosquare
You have maybe 10 or 11 different types of squares. Each has 4 boolean value allowing or not the 4 directions. This are datas for the full game, since the directions of a type of square doesn’t change.
But on the other hand, according to which square is there in n, path.n.typeofsquare will have to be defined.
I found a solution using a grid of instances of another object.
(that I already have for other functionalities)
It works when I build a path, but when I leave gaps to fill later, it only works partially and has random bugs, it stop filling connected squares correctly. Why?
I’ve also tried it with less than 50 repeats, so there shouldn’t be a timing problem?
Okay thanks i will take a look.
And i just figured out what was the problem with my code.
it starts from zero, so of course smaller IDs which later come true, can’t work.