Is this C?
If you have arraydata[12*12], then arraydata[x,y] is incorrect C (it will compile and give you arraydata[y]).
You either need
arraydata[x+y*12]
or you need
arraydata[12][12]
and
arraydata[x][y]
Jim
Hello Jim,
yes, the code snip is C#... Btw, i dont want a 1D array like array[12*12] for something like a map.... A 2D array like array[12,12] is more easy to handle and i dont need MULs to get/set x/y position.
In C# i have to write following for a 2D array, which works all fine:
int[,] arraydata = new int[12, 12]; // Works fine and easy to use for (level)maps i.e.
...fill arraydata with random values between between 0 and 1
// -------- Find first top/left position of wanted object/value
selectedObject = 1;
for (int y = 0; y < 12; y++)
{
for (int x = 0; x < 12; x++)
{
if (arraydata[x, y] == selectedObject)
{
startPos.X = x;
startPos.Y = y;
x = 13;
y = 13;
}
}
}
Now i have the startPos.X and startPos.Y of the first top/left object. Until here all works fine as i want/need...
Next i will check if there are neighboars filled with 1 and if so, how many. I will get the
startPos and endPos of all neighboars (horizontal and vertical). This is what makes me crazy, even its so easy in theory. In a basic language i used a Repeat/Until loop for this and tried the same in C#, where it does not works. Maybe my fault.
Take a look at the three images which should represent my arraydata[12,12]... All white fields may be value 0... the red and blue fields may be value 1... My first step is to get the first top/left block (with value 1) - Until here all works fine.
My second step is to check if there are direct horizontal or vertical neighboars and if so to check where the last position is. So i have tint the wanted fields blue.. So i should get following results:
Map1:
--------------
startPosX = 3
startPosY =1
endPosX = 6
endPosY = 3
Map2:
--------------
startPosX = 3
startPosY = 3
endPosX = 7
endPosY = 3
Map3:
--------------
startPosX = 3
startPosY = 3
endPosX = 4
endPosY = 7
Following code to check of endPos will not work.
do
{
endPos.X = startPos.X + tempX ;
tempX++;
} while (leveldata[endPos.X, startPos.Y] == selectedObject);
do
{
endPos.Y = startPos.Y + tempY ;
tempY++;
} while (leveldata[startPos.X, endPos.Y] == selectedObject);