Well, I am parsing over a 2D array. What I want to do is that when I index into the array, I get a value of 1, I move one hex space along a grassy sprite path. However, when I try to move in a water or mountain path it does not move, which is what I want it to do. It indexes into a value of 0 or 2. My problem is that when I increment Xloc it does not move the tank sprite but then the Xloc variable increments to a HexType value of 1. In other words, I want the array of 1 value to be the path and the values of 2 and 0 to be obstacles. let me know if need you more explanation.
if(rotate_tank==3)
{
drawTank_one = false;
Xloc++;
HexType = HexGrid[Yloc][Xloc];
if (HexType == 1)
{
move_x += 15.0f;
}
cout << Yloc << " " << Xloc << " " << HexType << endl;
}
if (rotate_tank == 0)
{
drawTank = false;
Xloc--;
HexType = HexGrid[Yloc][Xloc];
if (HexType == 1)
{
move_x -= 15.0f;
}
cout << Yloc << " " << Xloc << " " << HexType << endl;
}
if (rotate_tank == 2)
{
drawTank_two = false;
++Xloc;
++Yloc;
HexType = HexGrid[Yloc][Xloc];
if (HexType == 1)
{
move_x += 8.0f;
move_y += 13.5f;
}
}
if (rotate_tank == 1)
{
drawTank_three = false;
--Xloc;
++Yloc;
HexType = HexGrid[Yloc][Xloc];
if (HexType == 1)
{
move_x -= 8.0f;
move_y += 13.5f;
}
}
if (rotate_tank == 4)
{
drawTank_four = false;
++Xloc;
--Yloc;
HexType = HexGrid[Yloc][Xloc];
if (HexType == 1)
{
move_x += 8.0f;
move_y -= 13.5f;
}
}
if (rotate_tank == 5)
{
drawTank_five = false;
--Xloc;
--Yloc;
HexType = HexGrid[Yloc][Xloc];
if (HexType == 1)
{
move_x -= 8.0f;
move_y -= 13.5f;
}
}
break;
case GLUT_KEY_DOWN:
if (rotate_tank == 3)
{
drawTank_one = false;
move_x -= 15.0f;
}
if (rotate_tank == 0)
{
drawTank = false;
move_x += 15.0f;
}
if (rotate_tank == 2)
{
drawTank_two = false;
move_x -= 8.0f;
move_y -= 13.5f;
}
if (rotate_tank == 1)
{
drawTank_three = false;
move_x += 8.0f;
move_y -= 13.5f;
}
if (rotate_tank == 4)
{
drawTank_four = false;
move_x -= 8.0f;
move_y += 13.5f;
}
if (rotate_tank == 5)
{
drawTank_five = false;
move_x += 8.0f;
move_y += 13.5f;
}
break;
}
int HexGrid[12][10] = { {0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{2,2,2,2,2,0,1,1,2,2},{0,0,2,2,0,1,0,1,0,0},
{0,0,0,3,1,0,1,0,0,0},{0,0,2,1,1,0,1,0,0,0},{2,2,2,2,2,1,0,0,0,2},{0,0,0,2,2,1,0,0,1,1},
{2,2,0,0,2,1,0,1,0,0},{0,0,0,2,2,0,1,1,0,0},{0,0,0,2,2,2,1,0,0,2},{0,0,0,0,0,0,0,0,0,0} };
int Xloc = 9, Yloc = 7;
int HexType = HexGrid[Yloc][Xloc];