PDA

View Full Version : OpenGL problem (C) "Rodents Revenge 3D"


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();
}

Simon
06-01-2008, 05:55 PM
Hi Emma (wait is this the Emma Wilson i know?!)

Its hard too see what might be causing the problem which such a small snippet. Why not print the contents of the array at every iteration of you code to check the array values are correct?

I also notice nothing is being passed into your display function? Are you using a global array? try to avoid globals they are messy.

Use something like this instead.

// function prototype for two dimensions with pointer
void function(int (*a)[20]);
// create the array
int array[10][20];

//use of the function
function(array);

Cheers

-Si

CGTalk Moderation
06-01-2008, 05:55 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.