Problems with Wait Function
In my snake game, I finally got everything to work except there are a few minor errors. One thing is that my snake is stops for about 1-2 seconds every once in a while. I know why it is caused, but not really sure. It is because of the Wait function in timers.h. I can mail you my program, but here is my code.
int main()
{
SetMode(MODE_4 | OBJ_ENABLE | OBJ_MAP_1D | BG2_ENABLE);
int x;
DrawBG();
LoadOBJPalette();
InitializeSprites();
sprites[0].attribute0 = COLOR_256 | SQUARE | posy;
sprites[0].attribute1 = SIZE_8 | posx;
sprites[0].attribute2 = 512;
for(x = 8192; x < 8320; x++)
{
OAMData[x] = snakeData[x-8192];
}
while(1){
GetInput();
if(counter == 1)
{
if(posy >= 25)
posy-=5;
Wait(7500);
}
if(counter == 2)
{
if(posy <= 141)
posy+=5;
Wait(7500);
}
if(counter == 3)
{
if(posx >= 15)
posx-=5;
Wait(7500);
}
if(counter == 4)
{
if(posx <= 215)
posx+=5;
Wait(7500);
}
MoveSprite(&sprites[0]);
CopyOAM();
WaitForVsync();
}
}
You might want to post the source for this Wait function if you can. I have no idea what it does, so I can''t say what it''s doing.
-Arek the Absolute
-Arek the Absolute
/************************************\
* Timers.h by dovoto *
\************************************/
#ifndef TIMERS_H
#define TIMERS_H
#define TIME_FREQUENCY_SYSTEM 0x0
#define TIME_FREQUENCY_64 0x1
#define TIME_FREQUENCY_256 0x2
#define TIME_FREQUENCY_1024 0x3
#define TIME_OVERFLOW 0x4
#define TIME_ENABLE 0x80
#define TIME_IRQ_ENABLE 0x40
#endif
All right and here is our simple function to wait a few seconds
void Wait(int seconds)
{
//Start the timer
REG_TM3CNT = TIME_FREQUENCY_1024 | TIME_ENABLE;
//zero the timer
REG_TM3D = 0;
while(seconds--)
{
while(REG_TM3D <= 16386){} //wait
REG_TM3D = 0; //reset the timmer
}
}
* Timers.h by dovoto *
\************************************/
#ifndef TIMERS_H
#define TIMERS_H
#define TIME_FREQUENCY_SYSTEM 0x0
#define TIME_FREQUENCY_64 0x1
#define TIME_FREQUENCY_256 0x2
#define TIME_FREQUENCY_1024 0x3
#define TIME_OVERFLOW 0x4
#define TIME_ENABLE 0x80
#define TIME_IRQ_ENABLE 0x40
#endif
All right and here is our simple function to wait a few seconds
void Wait(int seconds)
{
//Start the timer
REG_TM3CNT = TIME_FREQUENCY_1024 | TIME_ENABLE;
//zero the timer
REG_TM3D = 0;
while(seconds--)
{
while(REG_TM3D <= 16386){} //wait
REG_TM3D = 0; //reset the timmer
}
}
I would like to know what all those calls to wait() are for. If you''re working on a system as (relatively) advanced as the GBA, you should never need to wait for anything except for VSync.
Anthony Serrano
Anthony Serrano
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement