#5859 - Dae - Sun May 11, 2003 12:16 am
I've been debugging this code for awhile now and I can't figure out what is wrong. It is supposed to handle collision detection and move the player around on the screen but for some reason it just sets the player at (0,0) and then stops them from moving. However when in uncomment those three lines or use local variables instead of the guy struct it will work fine. Im using DevKit Advance R5 if that makes any difference.
I compile it like this:
Setup code and game loop:
and in case you are wondering about the guy variable:
I compile it like this:
Code: |
gcc -o main.elf main.c bios.s libgbfs.c ..\..\vba.s -mthumb-interwork -mthumb -O3 |
Code: |
void GetInput(void)
{ s16 newx, newy; newx = guy->mapX; newy = guy->mapY; //char str[256]; //sprintf(str, "mapX: %d, mapY: %d, newx: %d, newy: %d\n", guy->mapX, guy->mapY, newx, newy); //vbalog(str); if(renIsKeyPressed(KEY_UP)) newy = guy->mapY - 1; if(renIsKeyPressed(KEY_DOWN)) newy = guy->mapY + 1; if(renIsKeyPressed(KEY_LEFT)) newx = guy->mapX - 1; if(renIsKeyPressed(KEY_RIGHT)) newx = guy->mapX + 1; if((guy->mapX != newx) && TestCase(newx, guy->mapY)) guy->mapX = newx; if((guy->mapY != newy) && TestCase(guy->mapX, newy)) guy->mapY = newy; guy->x = guy->mapX; guy->y = guy->mapY; renUpdateSprite(guy); // update mirrored OAM from rensprite struct } boolean TestCase(s16 xPos, s16 yPos) { return (backgrounds[0].cmap[((yPos + 4) / 8) * 32 + (xPos / 8)]==0) && (backgrounds[0].cmap[((yPos + 4) / 8) * 32 + ((xPos + 15) / 8)]==0) && (backgrounds[0].cmap[((yPos + 15) / 8) * 32 + (xPos / 8)]==0) && (backgrounds[0].cmap[((yPos + 15) / 8) * 32 + ((xPos + 15) / 8)]==0); } |
Setup code and game loop:
Code: |
guy->mapX = 110;
guy->mapY = 110; guy->x = guy->mapX; guy->y = guy->mapY; renUpdateSprite(guy); renCopyOAM(); while(gameRunning) { GetInput(); renWaitForVSync(); renCopyOAM(); } return 0; |
and in case you are wondering about the guy variable:
Code: |
typedef struct _RENSPRITE
{ s16 x; s16 y; s16 mapX; s16 mapY; u8 OAMIndex; } RENSPRITE, *LPRENSPRITE; |