#4823 - Unciaa - Fri Apr 11, 2003 12:36 am
I've written a simple tile-based display engine [32x32 VRAM area, actual map area of undefined sizes, yadayada...] and have started implementing a primitive collision engine [for now assuming my main sprite will always be in a certain position on screen, will see if I need more later].
Now while testing for tile data at coordinates works perfectly, I hit some problems when I try to do them per-direction. This is the relevant code...
What the program so far is supposed to do is point a pointer to our current map data, fill the VRAM 32x32 area with appropritate tiles given the starting coordinates [in our case 16x16, so the upper left corner is two tiles right and two tiles down], then just run a character control module.
The character control module creates a 16x16 sprite roughly in the middle [7x5th tile], then runs a loop in which it
-fetches the key direction [1=up 2=down 3=left 4=right 0=else], waits for sync, then if the direction is 1 checks if the tile above us is the designated blank tile. If it is we scroll the screen in the given direction for the [scroll] amount of tiles, reset the direction, then rinse and repeat.
[I'm just using this method until I get around to implementing double buffering... So no excessive flaming on it ;)]
The problem is, if I use
if(direction==1){}
for some reason the screen [at boot up] displays at the very upper left corner, then jumps to the correct position once I move. If I replace that with
if(1){}
the screen displays at the given coordinates correctly.
What the heck? Am I overwriting one memory location with another? I'm pretty sure I'm not [there are 6 integer global variables, one const u8 pointer and the OAM stuff]... Perhaps I'm not taking in account GBA's lag with certain things, but I fail to see what the problem is. Especially since testing for something produces different results from just saying "always", even though we start off the same and that if loop isn't even ran at that time. Help?
Now while testing for tile data at coordinates works perfectly, I hit some problems when I try to do them per-direction. This is the relevant code...
Code: |
void charcontrol(int direction, int scroll){ int terminator=1; u16 x; CopyOAM(); while(terminator){ direction=GetInput(direction); WaitForVsync(); if(direction==1){ x=fullmapX/8+14+(fullmapY/8+9)*mapsizeX; if((map[x] == 0x16)) scrollscreen(direction, scroll); } direction=0; } } int main(void){ REG_BG0CNT = CHAR_BASE(1) | BG_MOSAIC_ENABLE | BG_COLOR_256; SetMode(MODE_1 | BG0_ENABLE | OBJ_MAP_1D| OBJ_ENABLE ); int i, direction=0, scroll=2; map=map1; MakeSPRITE(); MakeBKG(); InitializeSprite1(); while (1){ charcontrol(direction, scroll); } } |
What the program so far is supposed to do is point a pointer to our current map data, fill the VRAM 32x32 area with appropritate tiles given the starting coordinates [in our case 16x16, so the upper left corner is two tiles right and two tiles down], then just run a character control module.
The character control module creates a 16x16 sprite roughly in the middle [7x5th tile], then runs a loop in which it
-fetches the key direction [1=up 2=down 3=left 4=right 0=else], waits for sync, then if the direction is 1 checks if the tile above us is the designated blank tile. If it is we scroll the screen in the given direction for the [scroll] amount of tiles, reset the direction, then rinse and repeat.
[I'm just using this method until I get around to implementing double buffering... So no excessive flaming on it ;)]
The problem is, if I use
if(direction==1){}
for some reason the screen [at boot up] displays at the very upper left corner, then jumps to the correct position once I move. If I replace that with
if(1){}
the screen displays at the given coordinates correctly.
What the heck? Am I overwriting one memory location with another? I'm pretty sure I'm not [there are 6 integer global variables, one const u8 pointer and the OAM stuff]... Perhaps I'm not taking in account GBA's lag with certain things, but I fail to see what the problem is. Especially since testing for something produces different results from just saying "always", even though we start off the same and that if loop isn't even ran at that time. Help?