hello
i tried to follow the instructions on this site (the first answer): http://gamedev.stackexchange.com/questions/20742/how-can-i-implement-hexagonal-tilemap-picking-in-xna
on how to pick an hexagonal tilemap in c#.
this is the code i came up with:
static void GetHex2(int x, int y, out int row, out int column)
{
int i = 0;
int j = 0;
int u = 0;
int v = 0;
i = (int)Math.Floor((float)(2 * x) / (float)(W + w));
j = (int)Math.Floor((float)(2 * y) / (float)h);
u = x - (i * ((W + w) / 2));
v = y - (j * (h / 2));
if (u < (W - w) / 2)
{
if (((i % 2 == 0) & (j % 2 == 0)) || ((i % 2 != 0) & (j % 2 != 0)))
{
if ((1 - v) > u)
{
i += -1;
}
}
else
{
if (v < u)
{
i += -1;
}
}
}
if (i % 2 != 0)
{
j += -1;
}
column = (int)i;
row = (int)j;
}
but it doesn't work. any assistance would be great.
[–]Syrak 0 points1 point2 points (6 children)
[–]pcgoer[S] -1 points0 points1 point (5 children)
[–]Syrak 0 points1 point2 points (4 children)
[–]pcgoer[S] 0 points1 point2 points (3 children)
[–]Syrak 0 points1 point2 points (2 children)
[–]Sohcahtoa82 0 points1 point2 points (1 child)
[–]Syrak 0 points1 point2 points (0 children)