No, you do not have to call or setup glutTimerFunc before main.
There are two basic ways to handle your movement, I guess in the future you want to have the tank fight something???
So the best solution would be to use the glutTimerFuncion for event and animation loop.
Once the game starts or in a initilize game routine start the glut timer.
glutTimerFunc( 100, My_timer_func, 0);
void My_timer_func( int te )
if (current_location != destination_location)
update_tank() // we only update when there is a new destination
update_enemy_tank(); // would have some logic to make it move or target the players tank
glutPostRedisplay(); //Update screen with new position data.
glutTimerFunc( 100, My_timer_func, 0);// restart the timer
In you keyboard routine, just add the corrent new position in which you want your tank to go in destination_location variable.
Then each update add a small movement until the current_location is equal to the destination.
To stop the timer just do this:
if ( game_over ) glutTimerFunc( 100, My_timer_func, 0);
Only when game_over variable is zero will the loop stop. So at start of game, set game_over to 1, then at the end switch to zero to stop it.
But you may want to keep it running to some animation or other things you may want to keep going when the game is idle.
In the timer loop could be something like this:
if (!game_over) Game_over_screen(); would only display at end of game
[This message has been edited by nexusone (edited 03-11-2004).]