For this question I would like to reffer to my previous thread: about my game project for school: http://www.daniweb.com/forums/thread102003.html.
I would like to execute a function every few miliseconds. Say every 5 miliseconds.
This part should call every 5 miliseconds.
bool Render() { // Render all the 20 fishes for(int i=0; i<20; i++) DrawTheFish(fish[i].x, fish[i].y); // Render the hook DrawTheHook(hook.x, hook.y); }
This is the function where you render to the screen. This fuction should be call in every 10 miliseconds or 5 miliseconds (up to you)
The problem is that I can't figger out how to run a function every 5 miliseconds...
I tryed some different idees. Those are the most promosing:
1) This one starts, takes some time, prints 5 lines at once.
void main() {
int i=0;
unsigned long timer=0, sw_timer;
printf("test test \n---------\n");
while(i<5){
timer=clock()/CLK_TCK;
if(timer==2) {
printf("do something\n");
timer = 0;
i++;
}
}
}
2) This is beter. its a little "flashing" but it gets the job done. But I can't use this cause the game dosn't have a fix timelimit.
void main() {
int i=0;
unsigned long timer=0, sw_timer;
while(i<5){
timer=clock()/CLK_TCK;
sw_timer=timer*10;
switch(sw_timer){
case 0: printf(" X \n\n"); clrscr(); break;
case 10: printf("X \n\n"); clrscr(); break;
case 20: printf(" X \n\n"); clrscr(); break;
case 30: printf(" X\n\n"); clrscr(); break;
case 40: printf(" X \n\n"); clrscr(); break;
case 50: printf("X \n\n"); clrscr(); break;
default: printf(""); clrscr();
}
}
}
any ideas? To bad I have to do this in C and not in C++ pffft
(teacher only accepts projects written in C)
AbberLine