Meecho
06-01-2008, 01:11 PM
I have a bit of a strange problem with my openGL game code. the movement and display is done through a 2d array, hence the levelarray[][] stuff. So when the array is a number 4, it displays a cat and when its a 5, it displays a cheese object.
When it enters the if loop (when the cat gets trapped), it sets the current cat position (cx and cy) to a couple of temp values. It then changes the cats position to jump to position 3,3 on the grid, making the place where it just left leave a number 5 (a cheese).
The print statement in the code prints fine and prints the exact position where the cheese should be, but for some reason, when the code goes to display(), it wont actually display the cheese.
But the strangest thing is, if i was to change levelarray[tempcx][tempcy] to, say, levelarray[2][2], it will display the cheese at position 2,2 with no problems.
Can anyone help with this?
Thankyou :)
if(levelarray[cx+1][cy]==2 && levelarray[cx-1][cy]==2 && levelarray[cx][cy+1]==2 && levelarray[cx][cy-1]==2)
{
int tempcx=cx;
int tempcy=cy;
printf("tempcx: %d\n", tempcx);
printf("tempcy: %d\n", tempcy);
cx=3;
cy=3;
levelarray[cx][cy]=4;
levelarray[tempcx][tempcy]=5;
display();
}
When it enters the if loop (when the cat gets trapped), it sets the current cat position (cx and cy) to a couple of temp values. It then changes the cats position to jump to position 3,3 on the grid, making the place where it just left leave a number 5 (a cheese).
The print statement in the code prints fine and prints the exact position where the cheese should be, but for some reason, when the code goes to display(), it wont actually display the cheese.
But the strangest thing is, if i was to change levelarray[tempcx][tempcy] to, say, levelarray[2][2], it will display the cheese at position 2,2 with no problems.
Can anyone help with this?
Thankyou :)
if(levelarray[cx+1][cy]==2 && levelarray[cx-1][cy]==2 && levelarray[cx][cy+1]==2 && levelarray[cx][cy-1]==2)
{
int tempcx=cx;
int tempcy=cy;
printf("tempcx: %d\n", tempcx);
printf("tempcy: %d\n", tempcy);
cx=3;
cy=3;
levelarray[cx][cy]=4;
levelarray[tempcx][tempcy]=5;
display();
}
