Hello,
Actually, I have a problem with an algorithm which consist to fill a surface. In order to do this, I have an 2D array which each case represents a case in my array. Besides, each case of my array are also represented by a state.
And I want to say that if there is a form (like a square or a triangle) on the map when the player walk and create a geometric shape.
About the state, if the player walk once on the square (array*[j]) the state is 1.1, twice : 1.2 and >= 3 the state is 1.3. And then if he walks three times in order to draw a square then inside the square it can be a state between 1.1 and 1.3 but my algorithm must say “ok then here there is a square”.*
I know it’s not obvious to understand but maybe with the algorithm you will see better.
Then my algorithm is :
```
-
void check(ref IsoCollision iso_collision, float i, float j, ref int z) // check if array[i][j] is inside a geometric shape { if ((i == 0 || j == 0 || i == 3 || j == 3) && get_state(i,j) != 1.3f) // if we are on the extremity and the state is not maximum then we are no inside a geometric shape, thus we quit { z = 0; return; } if (get_state(i, j) < 1.3f) { GameObject Case = GameObject.Find ("Floor_" + i + "x" + j); if ( Case.GetComponent<IsoObject> ().position.x == i && Case.GetComponent<IsoObject> ().position.y == j) Case.GetComponent<IsoBoxCollider> ().state *= -1; // in order to remember what this algorithm change case z++; // And then reccursif call check(ref iso_collision, i+1, j, ref z); check(ref iso_collision, i-1, j, ref z); check(ref iso_collision, i, j+1, ref z); check(ref iso_collision, i, j-1, ref z); } }*
* *And when I do :* *check(ref iso_collision, 0, 0);* *no error, but i want to browe my array thus I do :* *
*for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
check(ref iso_collision, i, j);
for (int x = 0; x < 10; x++)
for (int y = 0; y < 10; y++)
if (get_state(y, k) < 0)
Case.GetComponent().state = -1; / in order to reset all the state /
if (z != 0)
{ / Do something, that is to say there is a shape /
}
}
* *And with this I had "StackOverFlow Exception". (Then in C++ it's works perfectly with a simple array of std::string and the state 1.3 represent the "X";* *
*----------
| XXXXXXX|
| X X|
|X X|
|XXXXX X|
| X X|
| XXX X|
| XX|
| |
| Output : 1 : 2* |
| ``` |
| Indeed, array[1][2] is inside a shape |
| Thank you ! |